# Question
Title: Reformat external Date-Format to unix-timestamp / ee-compatible format
I have a date-field where I get some raw data from another system (I have no control over the export of the other system) … the date is published in the following format:

```
2010-10-26T07:11:18Z

```

Is there a way to easily convert this format into a unix-timestamp/ee-compatible format?

I've tried `{exp:query sql="SELECT UNIX_TIMESTAMP('col_id_22') AS unixtime FROM exp_matrix_data WHERE entry_id = {entry_id}"}{unixtime}{/exp:query}` but this does not work (I guess because of the `T` and `Z` in the raw data?

# Answer
If displaying, one option could be to use the Nice Date plugin by low http://gotolow.com/addons/low-nice-date/docs which will displays date given a formatting.
> 4 votes

---
Tags: php, mysql, time
---


# Question
Title: What does "Enable Strict URLs" really mean?
What does "Enable Strict URLs" really mean and are there any security/other implications if I choose to not use strict URLs?

# Answer
My URL schematic points out the difference it makes to the regular flow - might be helpful:

http://www.jamessmith.co.uk/articles/expressionengine\_url\_schematic

As you can see from the diagram, it prevents EE from determining a template via ~~methods #2 and #4~~ method #2 as numbered there (and as alluded to in the other answers).

For me the benefit of more reliable 404's doesn't outweigh the advantage of being able to determine a template in ~~these ways~~ this way, so I never enable it.

\[answer corrected May 2013 - You CAN have Strict URLs turned on and still use method #4.\]
> 19 votes

# Answer
With Strict URLs off, if your first segment doesn't correspond to an existing template group, EE will then look for a template with the same name in your *default* template group, and render that template if found.

Enabling Strict URLs prevents the behaviour - if `{segment_1}` is not a template group (and your URL is not a Pages URL), you'll get a 404.
> 9 votes

# Answer
My understanding of strict urls is as follows:

Lets say you have a news template/channel.

if you go to site.com/news/ this (assuming you've coded it so) will show you a list of all news items on the page.

You now have a site.com/news/view/url\_title\_here which is a single list page based on the last segment being the URL\_TITLE of the news item.

My understanding with strict URL's is that if you were to go to site.com/news/view/ without strict url's being enabled, it would simply show the 'latest' news item - however with it enabled, it will error/404.

At least thats always been my understanding.
> 5 votes

# Answer
Backing up a little: My understanding is that Strict URL's were implemented because of duplicate content\* issues - duplicate content is rarely an issue at all anyway. Google will just decide to index 1 page. It would be possible to run into a canonical issues but again that's rare.

* Different duplicate content than copying other sites and trying to out rank for that content.

Personally i don't run strict urls as it makes url's ugly although- by reading above i need to revisit and test a few things for clarification in my mind how exactly it works.
> 1 votes

---
Tags: templates, settings
---


# Question
Title: KREA HelpDesk plugin won't let me attach PHP files
I'm using the KREA HelpDesk plugin. Sometimes when I send a response I want to attach an updated file for the customer to test.

If I try to attach a PHP file to the ticket, I get the message "Error: This file type is not allowed". I can understand the security issue here, files shouldn't be uploaded to the server with the php extension because users could run them. However:

* There are ways around this, if the file was uploaded with a \*.bin extension or something it would mitigate the security issue.
* If I reply to ticket via email and attach a PHP file it works fine.

I've already tried disabling the notorious "Apply XSS Filtering to uploaded files" setting in EE. Has anyone else run into this? Is it a HelpDesk problem or an EE problem? Has anyone found a solution to let HelpDesk/EE accept \*.php uploads?

# Answer
> 5 votes
I'm not sure how KREA Help Desk does its verification for file uploads. I know that for the core of EE, if you've chosen to allow uploads of all file types, the file then goes through a check to see if the extension shows up in the mimes.php file in the config directory and whether it passed the aforementioned XSS check. I test uploaded a php file to a directory set to allow all file types, and it went in without a hitch, so either KREA is doing different checks, you're set up to allow a different set of filetypes, or somehow the php extension doesn't show up in your mimes.php file.

It's entirely possible that none of that helps you, but I do hope it can point you towards the right answer.

# Answer
> 4 votes
Currently, Helpdesk does not allow to upload PHP files. We have decided for this limitation to avoid a security issue when someone would email you PHP file, and by figuring out the path of attachments on your server, execute it.

Even though it's possible to block PHP execution for some folders (eg. via .htaccess), most of the users don't know this so we have decided to disallow PHP file attachments at the moment.

The workaround for this is to ask your users to send you PHP attachments in a .zip file.

---
Tags: uploads, attachment
---


# Question
Title: How can i order by a custom field in a channel entries tag?
I need to pull out all the entries in a channel that are of a certain type of category. But, i also want to be able to then sort the entries by the value of a custom field in that channel.

So right now, i have something like:

```
{exp:channel:entries channel="my_channel" limit="9" category="{segment_3_category_id}"}
     <li>{title}</li>
{/exp:channel:entries}

```

And in that channel, i have a custom field of "price". I want to amend that channel tag to order by my custom field called "price".

How can i achieve this?

# Answer
```
{exp:channel:entries channel="my_channel" orderby="price" sort="asc"}

```

Ordering entries by custom fields comes by default with ExpressionEngine: http://expressionengine.com/user\_guide/modules/channel/channel\_entries.html#orderby
> 17 votes

# Answer
One addendum to the other answers (though they are perfectly correct) that may be relevant to you given your choice of sorting field:

It's worth noting that if you want your `price` field ordered data to be ordered numerically in order of increasing/decreasing scale, you will need to change the field content type to decimal (assuming decimal prices). To do this go into your field settings, and you'll find "Field Content" under the "Field Options" section.

Otherwise these values:

```
 2,11,3

```

will end up sorted alphabetically like so:

```
11,2,3

```

when what you want is:

```
2,3,11

```
> 5 votes

# Answer
This is very easy to do Just order by your custom field - I do believe you are limited to fieldtype of "text" other fieldtypes won't work with the orderby parameter.

```
orderby="name_of_field"

```

See the docs.
> 1 votes

---
Tags: channel, filter
---


title: How to parse EE tag in Forums template?

text:
# Question
Title: How to parse EE tag in Forums template?
**EE tag in Forum template**

What I need is to use my custom EE plugin in to Forum header template: themes/forum\_themes/default/forum\_global/html\_header.html

I see that Forum template are processed by CI parser (is right?).

A workaround is include in html\_header.html a processed EE template, or call EE Template Class to process EE template.

What dou you think?

# Answer
Unfortunately, it's not possible to use regular EE tags in forum templates unless you run the forums through regular templates.

> The down side of this approach is that it adds more processing overhead, so it’s not recommended unless users really need this capability. Since the forum can’t be cached, on very busy sites this can create some unwanted server load.
> 4 votes

---
Tags: templates, parsing, codeigniter, forum, themes
---


title: Slow connecting to EE

text:
# Question
Title: Slow connecting to EE
I have a user complaining of slow connection to EE. It happens when the user clones an entry. It sometimes times out, sometimes it's just very slow. This is a homepage entry and it gets cloned frequently. Any thoughts?

# Answer
This is just an idea, but are you using NSM add-on updater? I have slow loading when this add-on gets stuck on when checking for an update. Alternatively , try disabling some accessories if you using any others.
> 2 votes

---
Tags: ee2
---


# Question
Title: Why is MX Google Map not resizing in tab?
I am using MX Google Map to display a basic map. This map happens to be in a tab (Bootstrap). Here is the code for the basic tab.

```
<div class="masthead-image tab-content">
    <div class="tab-pane fade" id="Map">{exp:stash:get name="location"}</div>
    <div class="tab-pane fade in active" id="Photo">{exp:stash:get name="masthead"}</div>
</div>

<ul class="unstyled">
    <li class="mapToggle"><a href="#Map" data-toggle="tab">View Map</a></li>
    <li class="mapToggle active"><a href="#Photo" data-toggle="tab">View Photo</a></li>
</ul>

```

The tabs are working fine, except that when I activate the map tab we get only a portion of a drawn map. To correct this issue I am attempting to trigger a resize event when the tab is activated... to no avail. Here is said code.

```
$('a[data-toggle="tab"]').on('shown', function (e) {
    google.maps.event.trigger(map, 'resize');
    map.setZoom( map.getZoom() );
 });  // refire the map

```

My question is why the event 'resize' is not happening as expected? I have a hunch that since MX Google Maps inserts the javascript for the map inline that it may be causing issue? I am, obviously not an expert here but would love some ideas or opinions

# Answer
I've found a solution. I needed to get the map id from the generated script from MX Google Map. Didn't need to set the zoom either. Learning as I go!

```
$('a[data-toggle="tab"]').on('shown', function (e) {
    for (var mapId in $.mxgoogleMaps.gMap) {
        google.maps.event.trigger($.mxgoogleMaps.gMap[mapId], 'resize');
        };
 });  // refire the map

```
> 4 votes

---
Tags: jquery, google-maps, mx-google-map
---


# Question
Title: Explaining (native) caching to mortals/new EE developers
A common area of confusion for developers new to EE is caching. EE provides a number of caching options that operate at different levels and can interact with each other, sometimes in unexpected ways. This tends to mean that performance **does not always automatically improve when using caching unless it is applied intelligently**. Understanding EE's caching behaviour is thus an important part of learning to use EE "properly".

So, **can you explain the different types of caching that ExpressionEngine provides, specifically their pro's and cons**, and **why you shouldn't *automatically* turn on caching here there and everywhere**, just because it sounds like a "good thing". *(I mean, everyone wants a faster website, right?)*

I know this is a complex topic, so do link to external resources, but it would be great to provide a general overview directly in the answers here as well.

*NB, While I appreciate that on some high traffic sites, paying extensive attention to caching/performance or even implementing Varnish or similar can make a lot of sense, for this answer I'm primarily interested in what makes sense as a baseline/starting point for a "normal" small/mid-sized ExpressionEngine site, and in using the native caching options that EE provides out of the box.*

# Answer
> 9 votes
Personally I recommend avoiding all current native EE caching systems and highly recommend investing in one or more of the already mentioned 3rd party caching systems. EE v2 did little if anything to make the dated EE v1 caching systems modern in any way, even if the CI framework has more modern caching systems available to it.

# Answer
> 12 votes
Native caching in EE basically comes down to:

* Tag Caching
* Query Caching
* Template Caching
* “Morsel” Caching
* Static Page Caching

All 5 types are explained in detail in this article on EEinsider: http://eeinsider.com/articles/using-cache-wisely-with-expressionengine/

Third party solutions include:

---
Tags: database, cache
---


# Question
Title: Expresso Store - Add free shipping when an order's subtotal is over an certain amount?
Is it possible to disable the shipping price if the order total is over a certain amount? I was thinking maybe a conditional in the checkout template but I havent gotten it to work. Does anyone have any ideas or could point me in the right direction? Thanks!

# Answer
> 10 votes
You didn't mention in the question you were trying to do this in addition to USPS.

The answer @MediaGirl gave would be correct if you were using the Default Shipping Plugin, as you can simply create extra rules to apply free shipping to orders over $50 (or whatever).

If you want to do this in combination with USPS rates, you will need to make a simple PHP shipping plugin which extends the USPS plugin and adds your custom rule.

For example, create a new file `third_party/store/libraries/store_shipping/store_shipping_usps_with_max.php`, with the following contents:

```
require_once dirname(__FILE__).'/store_shipping_usps.php';
class Store_shipping_usps_with_max extends Store_shipping_usps
{
    public function calculate_shipping($order)
    {
        // free shipping for orders over $50
        if ($order['order_shipping_subtotal_val'] >= 50)
        {
            return 0;
        }

        return parent::calculate_shipping($order);
    }
}

```

You should then be able to install and configure this new `Store_shipping_usps_with_max` plugin the same way you did the regular USPS plugin, but it will have the extra feature of free shipping on orders over $50

---

Another option if you don't want to go the PHP route, would be to simply add some conditionals to your checkout template, to automatically submit hidden fields for the free shipping method:

```
{if order_total_val > 50}
    <input type="hidden" name="shipping_method" value="id_of_free_shipping_method" />
{if:else}
    <input type="hidden" name="shipping_method" value="id_of_usps_shipping_method" />
{/if}

```

# Answer
> 10 votes
You don't need a conditional...

Set up a shipping method called Free Shipping using the Default Shipping Plugin.

Then set up the rules for this new shipping method... you'll want to set Minimum Order Total and Maximum Order Total specific to your use case. Then set your Base Rate charge to 0. Should do the trick.

Info on Shipping Methods is here in the docs: https://exp-resso.com/docs/store/settings/shipping\_methods.html

---
Tags: expresso-store, checkout, shipping
---


# Question
Title: How can I find out which add-on is sending a message to the developer log?
I'm working on a site that has a lot of add-ons, some probably redundant now. It is a very long term development project.

Since a recent EE update one of these add-ons is sending an error message to the developer log.

```
A third-party add-on is calling $this->load->library('security'), which is deprecated as the CI_Security class has been moved to Core, so it is always loaded.

```

This is great, but which add-on is it? How can I find out and is there a way to get the log to show slightly more useful information?

# Answer
> 9 votes
This came up on Stack Overflow recently and prompted a semi-official response:

> 1. This message will likely be removed in a future release. It's causing too much confusion than help and isn't entirely necessary. Yes it would be helpful for the developer log to let you know which addon is causing the problem, but the logistics of parsing backtraces to find that information proves to be difficult. Which brings us on to message #2:
> 2. As GDmac said, it's best to search your project for any calls to login\_form() in the CP controller. Normally a file and line number would be provided in this kind of message, but as I said, parsing backtrace info doesn't always work.
>
> We'll continue to try to make this better. The deprecation warnings have been working great for the most part, but occasionally messages like these pop up it can be difficult to know what to do about them.

---
Tags: add-on, error, developer-log
---


# Question
Title: Cartthrob: Save Customer Info Form problem, for guests
Recently, a client requested that their existing Cartthrob site now allow guest checkouts.

Currently it’s using a multi-page checkout. One page uses `{exp:cartthrob:save_customer_info_form}` and the next uses `{exp:cartthrob:checkout_form}`.

The problem lies on the first page. Previously I populated the form with the user’s details if they had it saved in their account, using Solspace User’s `{exp:user:stats}` tag. But now I need to support guest checkouts. The problem is that the `{exp:user:stats}` tag will hide its contents if the user is logged out.

So I basically repeat the code, but wrapped in the `{exp:user:stats}` tag if they are logged in. (This feels like the wrong way to do this, so if you have an alternative I’d love to hear it.)

```
{if logged_in}

 {exp:user:stats}

  {exp:cartthrob:save_customer_info_form required="..." return="cart/payment"}

   {var_checkout_fields}
   <input type="submit" class="button" value="Next Step" />

  {/exp:cartthrob:save_customer_info_form}

 {/exp:user:stats}

{if:else}

 {exp:cartthrob:save_customer_info_form required="..." return="cart/payment"}

  {var_checkout_fields}
  <input type="submit" class="button" value="Next Step" />

 {/exp:cartthrob:save_customer_info_form}

{/if}

```

Originally, the code was just what was inside the first conditional.

The form is displayed correctly for members and guests, but only members are able to proceed to the next page. When a guest hits submit, the page is just reloaded.

The Cartthrob setting “User must be logged in” is set to “no”, and I have set the appropriate member id for guest checkouts.

# Answer
> 4 votes
If you open up the CartThrob member settings you can assign customer fields to custom member fields. These values then pre-populate through the CT checkout process. For example, on a site I built recently the CT settings look like this:

Then, within my `{exp:cartthrob:checkout_form}` tag I have code like this:

```
<input type="text" name="first_name" id="first_name" value="{customer_first_name}" />

```

If the user is logged out or their `first_name` member field has not been populated then the value is left blank, so there's no need to create separate views for guests and members.

---
Tags: conditionals, checkout, cartthrob, solspace-user, guest
---


# Question
Title: Is the stash refresh variable the only means of breaking a cached set?
I'm trying to get into some more advanced use of Stash and I'm wondering about cache breaking. With some of the dedicated cache add-ons, you can set rules around cache breaking that are not simply time based - you can set a given cache to break when a new entry is added, for example - which is awfully handy.

My question is this - is Stash suitable for caching dynamic content on a basis other than time? My fear is that time would be a challenge for a site with certain channels being updated at much higher intervals than in others. The last thing i want to do is create a situation in which a client is confused by a recent entry not appearing in the site because the last page visit that was cached was only minutes before the most recent update was made and therefore the remaining time in the cache must expire before it breaks and is re-set and cached anew with a visit to the site. Just curious what the strategies are in using stash (or not) with caching.

# Answer
You can use the {exp:stash:destroy} {or it's alias {exp:stash:unset}) to unset a cached variable or variables within an entire scope (user or site): https://github.com/croxton/Stash/tree/dev#expstashunset-requires-php-523-or-expstashdestroy

Here's an example of use to clear cached comments when a new comment is submitted: https://gist.github.com/3973821

You may be able to find creative used of this tag to facilitate automatic cache clearing; for example, using the {edit\_date} variable as part of a variable name or context.

The tag is also available programmatically as Stash::destroy($params} where $params is an array of key=\>value pairs representing tag parameters. You can use this in a custom extension to clear cached variables on new entry submission or entry edit. I don't have an example to hand but I know some members of the EE community have already created extensions like this. Perhaps they could share the code below?

Finally, I'm in the early stages of writing a control panel module to manage automatic cache busting rules, which will also include an interface for manual cache clearing.
> 10 votes

# Answer
As you say, automatic cache breaking is very nice, and IMHO a must, since anything else is bound to impact the user experience for the editors. My goto caching addon since its release has been CE Cache, which solves this nicely.

For my 4–5 latest projects I've used the Template Partials approach (with Stash) increasingly. I love this way to develop in ExpressionEngine, but my main gripe is with caching. I feel that using Stash's own caching, and then having to code the breaking logic into the templates somehow, is way to fragile and hacky. Might work for smaller projects with few content types/variables, but not on more complex stuff.

So, I've continued to use CE Cache, with varying success. The problem is that you, naturally, **have to cache the "controller"-part of your templates, together with your "view"-part**, which, if you keep things DRY, means that you most of the time has to cache the whole page or nothing. This kinda defeats the whole point of CE Cache, which excels at caching more specific chunks of a page (or at least, that's where it excels in my opinion). The result is that you either have to break the cache more often (for all channels shown in a page, low variables, etc.), or you have to skip automatic cache breaking for some or all types of content (and leave it to the editor to do it manually). Neither is ideal.

On my latest project where I kept things very DRY, and the pages generally contained content from a lot of different channels, I'm left with the feeling that using the templates partials approach actually had a negative impact on the overall performance. But this is very project-specific, in many cases where you have simpler content, caching the whole page is perfectly OK.

I'm still trying to figure out what the optimal approach would have been, but I have a feeling that taking a step back and dividing the page into more (than one) native embeds, and thereby being able to cache separate parts of the page with CE Cache, would have been better. Not so pretty, but this is ExpressionEngine after all and sometimes it pays to work with the system instead of against it. Also, a parsed and cached embed isn't a performance issue.

Just my two cents.
> 5 votes

# Answer
Although Stash doesn't currently have automated cache breaking you can use the `{exp:stash:unset}` tag (docs) to flush caches when certain actions occur. For an example of this in use take a look at the top of Mark Croxton's sample viewModel template, where it's used to clear out cached comment data when a new comment is submitted.

The `Stash::destroy` method is also available statically, which means that creating custom cache-breaking extensions is fairly simple. I recently put together a very basic extension which flushes out all globally scoped caches whenever an entry or Low variable is updated. I was considering fleshing it out a bit more and releasing it 'properly' at some point, but if you'd like to see some sample code I've uploaded a gist to Github. I'm pretty sure it will only be compatible with the dev branch at the moment.

You should be able to implement additional triggers for cache breaking by inserting extra hook names into the `$hooks` array (so long as the hooks don't require a return value).

Although it is possible to create all sorts of complex site-specific cache breaking rules via some fairly simple extensions it doesn't change the fact that addons like CE Cache are far more powerful, with cache refreshing and support for multiple drivers built-in. On a high traffic site those features are likely to be essential, but on low-medium traffic sites, particularly those where content is updated infrequently, I'm increasingly finding that Stash is all that's needed.

\[I started writing this before Mark submitted his answer. There's quite a bit of overlap but I've written it now, so here goes anyway...\]
> 3 votes

---
Tags: stash, cache
---


# Question
Title: Simple conditionals parse when they shouldn't
I have a page that's set up like this:

```
{if segment_2 == ""}
  // show categories
{/if}
{if segment_2 != ""}
  // show entries
{/if}

```

I'm using simple conditionals ( as opposed to if:else ) because I don't want the contents of the second part to be parsed when they shouldn't.

But, when my segment\_2 is empty, EE still goes inside that tag and parses everything, resulting in a slow page load.

There's nothing out of the ordinary inside that simple conditional ( EE tags, an embed and a little bit of php ( parsed on output ) )

But **something forces EE to ignore the parsing error and parse everything inside the conditional**. Question is: what ?

I know I could probably just use switchee and be done with it, but I shouldn't have to. I want to figure out what goes wrong.

# Answer
It seems like putting an if:else inside your simple conditional makes it an advanced conditional, thus affecting parsing order.

In other words, suppose segment\_1 is empty:

```
{if segment_1 != ""}
   EE tags placed here won't be parsed
{/if}

```

vs.

```
{if segment_1 != ""}

   EE tags placed here WILL be parsed

   {if segment_1 != ""}
      // something here
   {if:else}
      // something here
    {/if}
{/if}

```

( luckily, we have switchee: http://devot-ee.com/add-ons/switchee )
> 9 votes

# Answer
I'd recommend you taking a look at Mark Croxton's if:else and switchee plugins. They allow you to use advanced conditionals (and switches) without the overhead of having all your conditions parsed, which is the default EE behaviour.

They're a fantastic way of optimising your site and I'd encourage you to start using them whenever you have a need for anything other than a simple conditional.

Here are the links to Mark's addons:

Take care

Jim
> 10 votes

# Answer
Conditionals are always parsed, they are only displayed if the condition is passed. If you want to avoid this behaviour you need to use IfElse by Croxton or switchee also by Croxton.
> 2 votes

---
Tags: ee2, conditionals, parse-order
---


# Question
Title: Displaying category information on a “Single Entry Page”
I’m completely stumped. I’m working on my first eCommerce website using the “Store Module”. The problem that I’m running into is in regards to Categories. I have setup a number or categories for the products. It happens to be a Vacuum store. Here’s my issue….

In the Central Vacuums category there are 7 sub categories that break this category down. (ie. canisters, powerheads, accessories, etc.). I am displaying the list of sub categories based on the URI segment (ie. if you are in the Central Vacuums category it displays the sub categories. I have gone one step further and am only displaying the sub categories that have been selected by at least 1 entry (ie. categories that have never been selected within an entry will not display in the sidebar).

The problem I’m having is that Once I choose a product and am moved to the “Single Entry” page for that specific product, the URI no longer displays the category information and my category and sub category information disappears.

Is there any way to show the category information on a “Single Entry” page?

Sorry this was so long winded. Very confused how to handle this.

```
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Title</title>
</head>
<!--BODY-->
<body>
       <h6>Products</h6>
        <ul>
            <li><a href="{path='products/index/c/central-vacuums'}">Central Vacuums</a></li>
            <li><a href="{path='products/index/c/portable-vacuums'}">Portable Vacuums</a></li>
            <li><a href="{path='products/index/c/carpet-steam-cleaners'}">Carpet/Steam Cleaners</a></li>
            <li><a href="{path='products/index/c/bare-floor-cleaners'}">Bare Floor Cleaners</a></li>
            <li><a href="{path='products/index/c/commercial-equipment'}">Commercial Equipment</a></li>
            <li><a href="{path='products/index/c/air-purification-equipment'}">Air Purification Systems</a></li>
            <li><a href="{path='products/index/c/parts-and-accessories'}">Parts & Accessories</a></li>
        </ul>
        <h6>Categories for </h6>
        <!--start of categories-->
        {if segment_3 =='central-vacuums'}
            {exp:gwcode_categories show="90|91|92|93|94|95|96|97" last_only="yes" show_empty="no"}
                <a href="#">{cat_name}</a>
            {/exp:gwcode_categories}
        {/if}
        {if segment_3 =='portable-vacuums'}
            {exp:gwcode_categories show="83|84|85|86|87|88|89" last_only="yes" show_empty="no"}
                <a href="#">{cat_name}</a>
            {/exp:gwcode_categories}
        {/if}
        {if segment_3 =='carpet-steam-cleaners'}
            {exp:gwcode_categories show="98" last_only="yes" show_empty="no"}
                <a href="#">{cat_name}</a>
            {/exp:gwcode_categories}
        {/if}
        {if segment_3 =='bare-floor-cleaners'}
            {exp:gwcode_categories show="99" last_only="yes" show_empty="no"}
                <a href="#">{cat_name}</a>
            {/exp:gwcode_categories}
        {/if}
        {if segment_3 =='commercial-equipment'}
            {exp:gwcode_categories show="100|101|102|103|104" last_only="yes" show_empty="no"}
                <a href="#">{cat_name}</a>
            {/exp:gwcode_categories}
        {/if}
        {if segment_3 =='air-purification-equipment'}
            {exp:gwcode_categories show="105" last_only="yes" show_empty="no"}
                <a href="#">{cat_name}</a>
            {/exp:gwcode_categories}
        {/if}
        {if segment_3 =='parts-and-accessories'}
            {exp:gwcode_categories show="106|107|108|109|110|111" last_only="yes" show_empty="no"}
                <a href="#">{cat_name}</a>
            {/exp:gwcode_categories}
        {/if}
        <!--end of categories-->
        <h6>Brands for </h6>
        <!--start of brands-->
        {if segment_3 =='central-vacuums'}
            {exp:channel:entries channel="products" category="90|91|92|93|94|95|96|97" status="featured|open"}
                {exp:playa:children field="brand"}
                    <li><a href="#">{title}</a></li>
                {/exp:playa:children}
            {/exp:channel:entries}
        {/if}
        {if segment_3 =='portable-vacuums'}
            {exp:channel:entries channel="products" category="83|84|85|86|87|88|89"}
                {exp:playa:children field="brand"}
                    <li><a href="#">{title}</a></li>
                {/exp:playa:children}
            {/exp:channel:entries}
        {/if}
        {if segment_3 =='carpet-steam-cleaners'}
            {exp:channel:entries channel="products" category="98"}
                {exp:playa:children field="brand"}
                    <li><a href="#">{title}</a></li>
                {/exp:playa:children}
            {/exp:channel:entries}
        {/if}
        {if segment_3 =='bare-floor-cleaners'}
            {exp:channel:entries channel="products" category="99"}
                {exp:playa:children field="brand"}
                    <li><a href="#">{title}</a></li>
                {/exp:playa:children}
            {/exp:channel:entries}
        {/if}
        {if segment_3 =='commercial-equipment'}
            {exp:channel:entries channel="products" category="100|101|102|103|104"}
                {exp:playa:children field="brand"}
                    <li><a href="#">{title}</a></li>
                {/exp:playa:children}
            {/exp:channel:entries}
        {/if}
        {if segment_3 =='air-purification-equipment'}
            {exp:channel:entries channel="products" category="105"}
                {exp:playa:children field="brand"}
                    <li><a href="#">{title}</a></li>
                {/exp:playa:children}
            {/exp:channel:entries}
        {/if}
        {if segment_3 =='parts-and-accessories'}
            {exp:channel:entries channel="products" category="106|107|108|109|110|111"}
                {exp:playa:children field="brand"}
                    <li><a href="#">{title}</a></li>
                {/exp:playa:children}
            {/exp:channel:entries}
        {/if}
        <!--end of brands-->
        <h6>Shop By Price for {last_segment_category_name}</h6>
        <hr>
            <ul>
                <li><a href="#">$0.00 - $99.99</a></li>
                <li><a href="#">$100.00 - $199.99</a></li>
                <li><a href="#">$200.00 - $399.99</a></li>
                <li><a href="#">$400.00 - $799.99</a></li>
                <li><a href="#">$800.00 and over</a></li>
            </ul>
        </li>
</body>
</html>

```

# Answer
> 7 votes
Generally in ExpressionEngine you don't keep the category information in the URL for your single entry page. This is because an entry can belong to more than one category, so you will end up with more than one URL for the same product, which is bad for SEO.

If you really want to do this, you might find Low's Seg2Cat helpful.

# Answer
> 6 votes
Well, you could get the list and info of categories you have assigned the entry to by Categories tag inside the Channels entry tag. Is this something on the way to the final goal?

# Answer
> 3 votes
It's not in the plugin documentation, but have you tried adding `dynamic="no"` to the tag?

---
Tags: expresso-store, categories, ecommerce, url, gwcode-categories
---


title: Upgrade Error 2.1.1 to 2.5.3

text:
# Question
Title: Upgrade Error 2.1.1 to 2.5.3
I'm in the middle of upgrading a site to 2.5.3 and just triggered the upgrade script when I recieved the following error.

```
A Database Error Occurred
Error Number: 1060

Duplicate column name 'show_sidebar'

ALTER TABLE exp_members ADD show_sidebar char(1) NOT NULL default 'y' AFTER quick_tabs

Filename: updates/ud_212.php

Line Number: 53

```

What is the best way to resolve this. I do have a back up and will revert back shortly if needed.

# Answer
So some quick googling, while MediaGirl was typing, found the answer here.

> When EE updates, it’s running through each update file in order, and those update files can be found at /system/installer/updates/. They look like ud\_231.php, where 231 is the version number that’s being updated. When EE finishes running through the routines in that update file, the database will effectively be at version 2.3.1. Does that make sense?
>
> If an update fails and you immediately reload the updater and run it again, it will not re-run any update file that has already been completed, but it will re-run an update file that has been started and didn’t complete. Now, what you want to do here is run the updater like normal from 2.1.1. **When you encounter a PHP or MySQL error that says it can’t add/remove/modify/database because it does/doesn’t exist (as the case may be), read what’s happening in that error and then go find the update routine that caused it. At this point, it’s a good idea to see what change the updater was trying to make and then go examine your database to see if that change has already been made. If it has, you comment out that part of the updater file, knowing it can skip that part since the change it wants to make has already been made**.
>
> Remember that re-running the updater at this point will start over at the beginning of the update file in which you experienced the error, so you’ll want to comment out of that update file the part that caused the error as well as any routines that came before it in that particular update file. Then go back and re-run the updater. You may need to do this a few times if there are a few spots in your database that had already been updated and cause an error this time around.
> 9 votes

# Answer
Either delete that show\_sidebar column in the DB or comment this query out in the upgrade script.
> 4 votes

---
Tags: ee2, error, upgrade
---


# Question
Title: How do I access custom config.php variables in a plugin?
I'm writing a plugin for which I'd like to be able to set site-wide preferences via custom variables in config.php (eg `$['myplugin_config_item']`), and have those variables available in all my plugins methods, eg:

```
...
class Myplugin {

  public $return_data;

  function Method(){
    //how do I access $['myplugin_config_item'] here?

  }
  function Method2(){
    //and if I want to access $['myplugin_config_item'] here too, what's the most efficient way to do so?
  }

}
...

```

What's the cleanest/neatest way to do this?

# Answer
> 20 votes
If you need to access a variable repeatedly then you should generally place it within a constructor method and assign it as a class property, rather than continuously checking config values. This approach also gives you the opportunity to set a default value which you can use class-wide if the config item is not found.

```
<?php
class Myplugin {

    var $return_data;
    var $my_setting;

    function __construct()
    {
        $this->EE =& get_instance();

        if($this->EE->config->item('my_setting') !== false)
        {
            $this->my_setting = $this->EE->config->item('my_setting');
        }
        else
        {
            $this->my_setting = "Default value if config value doesn't exist.";
        }
    }

    function one()
    {
        echo $this->my_setting;
    }

    function two()
    {
        echo $this->my_setting;
    }

}

```

# Answer
> 8 votes
Since ExpressionEngine is based on Codeigniter, you can use the CI Config class to fetch config items.

http://codeigniter.com/user\_guide/libraries/config.html

```
class Myplugin {

    public $return_data;

    function Method()
    {
        $this->EE =& get_instance();

        $item = $this->EE->config->item('myplugin_config_item');
    }

    function Method2()
    {
        $item = $this->EE->config->item('myplugin_config_item');
    }

}

```

---
Tags: add-on-development, config
---


# Question
Title: SafeCracker File: min-width/min-height for Images
Is there a way to set a «min-width» for images to a «SafeCracker File»-Field (type: Images)?

We have a SafeCracker-Form, where Users are allowed to upload Images — but these should have a min-size of 512x512 Pixels.

There are Settings for max-width/-height in edit\_upload\_preferences, but I haven't found settings for min-width/-height so far.

# Answer
Unfortunately the EE file upload library has no extension hooks you can use to add extra routines to the process of uploading files from outside the File Manager.

However, you could use SafeCracker's `safecracker_submit_entry_start` hook (docs) to inspect your upload (which will likely be in the `$_FILES` global variable), run `getimagesize()` on it (docs), and then if it doesn't meet your minimum requirements, return an error:

```
return $this->EE->output->show_user_error('submission', 'Your image does not meet the minimum size requirements.');

```

That should get you started.
> 7 votes

---
Tags: safecracker, settings, file-uploads
---


title: Nesting Playa tags several levels deep?

text:
# Question
Title: Nesting Playa tags several levels deep?
Does anybody know of a solution to nested playa tags?

Currently I believe that the only way to retrieve playa entires from within another playa tag pair is to use an embed, is this still the case? Can we circumvent this using Stash or something similar?

This is what I'd like to be able to do:

```
{exp:channel:entries channel="products" dynamic="yes"}
        {!-- Product specific stuff goes here --}

        {!-- My Playa fieldtype that relates other products to this one --}
        {cf_phone_similar_products}
        <article>
            <header>{title}</header>

            {!-- Each Product has a Related plan that I need to grab --}
            <p>Free on the {exp:playa:children field="cf_phone_free_with_a_plan"}{title}{/exp:playa:children}</p>
        </article>
        {/cf_phone_similar_products}

{/exp:channel:entries}

```

# Answer
Using the new var\_prefix (came in in version 4.2 IICRC) embeds have / can been done away with. Links to docs - http://pixelandtonic.com/playa/docs/templates

Example code:

```
{exp:playa:children channel="news" parse="inward" var_prefix="news"}
    {news:exp:playa:children channel="editors" var_prefix="editor"}
        {news:title} - {editor:title}
    {/news:exp:playa:children}
{/exp:playa:children}

```
> 11 votes

# Answer
I tried to do something similar with Stash but I finally rollback to an embed.

The main reason is that it was becoming hard to maintain and not effective as expected. Sometimes embeds are just the way to go, especially with nested complex template nesting tags.

Embeds are not always evil ;)
> 3 votes

# Answer
I think John's solution will work if all you need is "title", "entry\_id", "channel" but if you need to access a field you've defined in "Plan" you'll have to pass an embed:

```
{exp:channel:entries channel="products" dynamic="yes"}
    {!-- Product specific stuff goes here --}

    {!-- My Playa fieldtype that relates other products to this one --}
    {exp:playa:children field="cf_phone_similar_products" parse="inward" var_prefix="prod"}
    <article>
        <header>{prod:title}</header>

        {!-- Each Product has a Related plan that I need to grab --}
        <p>Free on the {exp:playa:children field="cf_phone_free_with_a_plan" var_prefix="plan"}{plan:title}{/exp:playa:children}</p>
    </article>
    {/exp:playa:children}

{/exp:channel:entries}

```
> 2 votes

---
Tags: stash, playa
---


title: Segments producing active class

text:
# Question
Title: Segments producing active class
I have a simple unordered list nav, it displays an active list item depending on segment\_1. Within that unordered list I have another unordered list with a class of 'sub'. For some reason, all list items display as active too in IE7, but not active class is within that list item.

I know its not fully an EE question, but has anyone ever seen this? Code is below:

```
<ul><li class="program"><a href="/program/" title="Program Overview">Program Overview</a></li>
<li class="tour active"><a href="/tour" title="Take a Tour">Take a Tour</a></li>
<ul class="sub">
    {exp:channel:entries channel="tour" limit="10" disable="categories|custom_fields|member_data|pagination" entry_id="not 41" dynamic="off"}
    <li><a href="{url_title_path=tour}" title="{title}">{title}</a></li>
    {/exp:channel:entries}
</ul>

```

# Answer
> 5 votes
This is a CSS issue I think. Try a CSS selector like ul \> li.active to make sure it's targeting just the first tier li.

---
Tags: css, navigation, segments
---


title: Channel Images - can't find other sizes

text:
# Question
Title: Channel Images - can't find other sizes
So I just purchased my first copy of Channel Images and installed it without issue. I then proceeded to add a field and then add images to an an entry. All went smoothly. However I can't seem to find out how to create different sized images. In the entry page there's a tab for SIZES but nothing happens when I click on it.

I used the following template code from the docs

```
{exp:channel_images:images}
  <a href="{image:url}"><img src="{image:url:medium}" /></a>
{/exp:channel_images:images}

```

Which spits out the following image url `<img src="{image:url:medium}">` Likely since I haven't created a medium image, but I don't see where to do this and there's no information in the documentation.

So my question is - how do I create different sized images using channel images and is there anything else that I am missing that is not in the docs.

# Answer
Creating a new size is pretty easy actually. It's done in the fieldtype settings.

This image should say it all.
> 5 votes

# Answer
You set up image sizes on the custom field edit form for your specific field.
> 2 votes

---
Tags: ee2, add-on, channel-images
---


# Question
Title: Default HTML Buttons not visible with IE8
I have a client who informs me that the Default HTML Buttons are not appearing with the field. I am using a mac with Safari and Firefox and they display no problem. Anyone else encountered this problem?

# Answer
> 5 votes
I haven't had this specific problem, but as a troubleshooting step, I'd see if the client is using the exact same CP URL that you are using - www vs not and admin.php vs system.

# Answer
> 3 votes
From the information you have provided, I can only give you the general steps that you would need to take to resolve such an issue with Ellislab.

Since this would likely be a bug, you would need to post a bug report to the bug tracker.

http://expressionengine.com/bug\_tracker/

However, you may want to confirm this through Ellislab's official support channel before posting a bug report.

If you can't wait, then you can also modify the control panel theme. Make a copy of the problem theme first, and then modify the copy.

http://expressionengine.com/user\_guide/development/cp\_styles/index.html

---
Tags: custom-fields, ie8, browser
---


# Question
Title: How do I format the date in a foreign language?
I currently have the task of building an EE site in Chinese. All is going well so far, but I have a problem trying to get the date shown in chinese. Anyone have a solution to this?

I'm just using the following standard date code at the moment:

```
{current_time format="%l %j%S %F, %Y"}

```

# Answer
Firstly - you need to check that your server has Chinese Encoding installed - if it does, then what you need is the plugin that I wrote many years ago:

Date/Time Language Converter

You can then use this plugin to wrap your date/time value and specify the language and it'll format it in the appropriate language.
> 10 votes

# Answer
You can also just install the Chinese language pack. This will also convert the CP to Chinese, but you can set a language preference per user to override it.
> 2 votes

# Answer
What format do you need to output?

So I'm not a Chinese speaker, so will very happily defer to anyone who knows more than me, but as I understand it the convention is to format the date "Year Month Day", with each value followed by the relevant character 年 (nián) for year, 月 (yuè) for month, and 日 (rì) for day. Assuming that you are using a utf-8 charset can you not just do: `{current_time format="%y年 %m月 %d日"}`

If you need to output the day of the the week or a more complex format though it looks like you might be best off with @madebyhippo's plugin, which looks super flexible.
> 1 votes

---
Tags: date
---


title: Field with huge amount of content

text:
# Question
Title: Field with huge amount of content
I have a custom field for some body text, but the content for one particular entry is so long that it gets chopped off, presumably because of the MySQL limit for columns of type TEXT.

I absolutely loathe pagination so that's not an option.

Would it be safe to simply switch the column's type to something like MEDIUMTEXT? It's a large site with thousands of entries so a bit nervous of messing around in the database.

Any other options?

James

# Answer
You can change the fieldtype to MEDIUMTEXT or LONGTEXT and it will work fine for your needs. But you need to be aware that that change will not be supported by EE and that future EE updates may alter the schema and of course could reset the fieldtype to TEXT.

Reference - http://expressionengine.com/forums/viewthread/211174/
> 13 votes

# Answer
Change the field type to LONGTEXT to give yourself lots of room to grow with that field.

LONGTEXT will store 4,294,967,295 bytes of data which is approximately ~4GB. Should be plenty.
> 6 votes

---
Tags: custom-fields, mysql, long-content, mediumtext
---


# Question
Title: How to create a complex stockist list using Structure and/or categories
After struggling for a day I hope that someone may be able to help me. I have a site that has a list of stockists worldwide. I would like to have a landing page where you can choose your country (grouped by regions) as per:

Oceania

* Australia
* New Zealand

United Kingdom

* England
* Scotland
* Wales

etc.

Currently there are 31 countries but the client needs to be able to add more. Some, but not all, need to also be broken down into states/counties (which the client can add to) but I don't want to be able to see all of these on the landing page as there a lot for some countries. When you select the country you need to be taken to a page specific for that country. Some will have a promotion displayed based on the country. Also on the country page will be a country distributor and either a list of retail stockists (some countries don't have any) or the ability to choose a state or county (as some countries have several states/counties with many retail stockists) which can then be selected to display that state or county's retail stockists.

I have been struggling with this for so many days now that this doesn't seem to make sense anymore - please let me know if you need further clarification.

What I would like to know is how you would set this up in EE which has Structure installed. Assets for each retail stockist? A page for the landing page, a page for the country? Would you use categories for the Region/Country/State? How would you then pull the data into the templates?

So far I have tried using categories for each retail stockist and they are being entered as assets on a country page. I have managed to create a landing page using GWCode Categories which links to the page, but none of the category information is passed to the page. Do I need to use another plugin to get the category information? How would I then display a list of states, if there are any, for that particular country? Am I over thinking this and there is a much simpler way?!

My landing page is stockists/index and has the following code displaying the categories so far (it's a responsive site so I have the countries set up in 3 columns):

```
                <div class="grids grids-three clearfix">
                <div class="grid grid-1 clearfix">
                    <div class="grid-a">
                        <h2>Oceania</h2>
                            <ul>
                            {exp:gwcode_categories
                                channel="stockists"
                                cat_id="26"
                                depth="2"
                            }
                            <a href="stockist-details/{cat_url_title}">{cat_name}</a>
                            {/exp:gwcode_categories}
                            </ul>
                    </div>

                    <div class="grid-b">
                        <h2>United Kingdom</h2>
                            {exp:gwcode_categories
                                channel="stockists"
                                cat_id="7"
                                depth="2"
                            }
                            <a href="stockist-details/{cat_url_title}">{cat_name}</a>
                            {/exp:gwcode_categories}
                    </div>
                    <div class="grid-c">
                        <h2>North America</h2>
                            {exp:gwcode_categories
                                channel="stockists"
                                cat_id="8"
                                depth="2"
                            }
                            <a href="stockist-details/{cat_url_title}">{cat_name}</a>
                            {/exp:gwcode_categories}
                    </div>
                </div>

```

The country page is stockists/stockist-details and contains the following code which only displays the ENTIRE list of countries and states/counties when you click through to it, but if you select one of the countries or states you get a list of stockist below the huge list of categories.

```
                <!-- STOCKIST DETAILS -->
            <div class="stockist-details">
                <header>
                    {exp:channel:category_heading channel="stockists"}
                    <h1>{category_name}</h1>
                    {/exp:channel:category_heading}
                </header>

                {exp:channel:categories
                    channel="stockists"
                    disable="member_data|pagination|trackbacks"
                }
                <a href="{path='stockists/stockist-details'}">{category_name}</a>
                {/exp:channel:categories}

                <div class="stockist-listing">
                    <ul>
                        {exp:channel:entries
                            channel="stockists"
                            disable="member_data|pagination|trackbacks"
                        }
                        <li>
                            <h3>{title}</h3>
                            <p>{stockist_address}<br />
                                {stockist_city} {postcode_zip}</p>
                            <p><span>Phone:</span> {stockist_phone}</p>
                        </li>
                        {/exp:channel:entries}
                    </ul>
                </div>
                <!-- / .stockist-listing -->

            </div>
            <!-- / #stockist-details -->

```

I hope that someone is able to make sense of all of this and make some suggestions as to where I'm going wrong, or a better approach. Thanks.

# Answer
I would only use categories for details about the retail outlet, like (I'm guessing here) payment types available, stock types available, etc.

I'd create 3 channels, 1) Country, 2) Region and 3) Retailer. Country and Region can use the same field group with just a body field, unless you need additional detail at their levels. I'd have at least a matrix field in the Retailer field group.

Within Structure, I'd set the Country channel to a page, with the Region channel as a child page of Country, and the Retailer channel would be a listing under Region. Asset would work as well, but pages and assets are on different tabs, so there's a bit of a disconnect.

Use the matrix field on the Retailer entry page for the retailer-specific content, and categories for common details to keep the matrix field manageable. Or, the retailer entry could be mostly category selections. There are always a few ways to go at things with EE.

This provides an entry interface for your client that's easy to navigate and update.

Haven't used NSM's add-on, but I's say that Low's Seg2Cat would be quite useful in this build.

Might be worthwile to work up a quick prototype with one of the current frameworks to test the logic before you get too far into content entry.
> 4 votes

# Answer
It's possible that just using pages in Structure will be easier, but a couple of things to consider if using categories: Low Seg2Cat and NSM Categories.
> 3 votes

# Answer
Are you able to use Playa and Matrix? If so you could approach this like so:

Your regions would either be categories assigned to a countries channel or they could simply be a select field with all the possible regions listed, even if they aren't used right now.

Each of these countries would then have a matrix list for handling the states. This also allows for more metadata about the states as well. Then in the stockists channel add an EE relationship field (or a Playa field if one stockist can be in multiple countries).

Then your templates simply use conditionals to determine what's being displayed to the user.
> 2 votes

# Answer
I'd say categories would work absolutely fine for this and if you ask me make sense. Along with Seg2cat this is another excellent categories handling add-on - http://devot-ee.com/add-ons/gwcode-categories.
> 1 votes

---
Tags: templates, structure
---


# Question
Title: Is there a plugin that will strip a bit of text out of a string?
I've got a variable like {current\_url} which contains the full url of the page you are on.

I want to strip out the last segment from it.

Is there a plugin or native EE way of doing that?

Say that variable is example.com/me/you and i want to remove the "you" from the end, how would i do that?

Due to variable url segments, i can't do {segment\_2}{segment\_3}{segment\_4} as "you" might be the second or third or fourth variable.

Thanks

# Answer
Found it, the brilliant @low strikes again with a great plugin called Low Replace!

Syntax like:

```
{exp:low_replace find="you" replace=""}{current_url}{/exp:low_replace}

```

Cool!
> 6 votes

# Answer
Low's stuff is allways awesome. I was thinking of this, pretty awesome too. http://www.causingeffect.com/software/expressionengine/ce-string?
> 7 votes

# Answer
You could also try PHPStringFun and the str\_replace function. PHPStringFun lets you run php functions on the template without enabling PHP.

It'll be overly complex for this but is useful if you need to do anything more than just replace text (or use any other phpfunctions).
> 4 votes

# Answer
Surgeree also does regex replace.
> 2 votes

---
Tags: url, variable
---


title: URL for template pages?

text:
# Question
Title: URL for template pages?
I created a static page using just template files. For example, say I have the following:

`/pages/faqs/`

The page is accessible via `http://www.domain.com/index.php/pages/faqs`. What if I wanted the URL to be `http://www.domain.com/index.php/foo/`? Is there a way to set this?

# Answer
So as with almost everything in EE, there are lots of ways to do this. Here are a few options, roughly sorted by ease of implementation. What's right for you will depend on the complexity of your particular build and your comfort level:

*Personally I'd avoid using .htaccess for this kind of static routing, although it will probably work fine it takes routing out of your app and puts it in your server config, which always seems wrong to me when there are native options available.*

* If your foo template is in your site's default template group, and you have "strict URLs" set to off in your global template prefs, your foo template should automatically be available at /foo
* Use the pages module, creating an entry with a URL of /foo that uses that template.
* Use an addon like structure, NavEE to manage your navigation/URL structure
* use a "controller" template as your site's index template, that inspects the URL and routes various values to different template via embeds:

... {if segment\_1 == "foo"} {embed="pages/foo"} {/if} ...
* Use Freeway to give you full routing control independent of templating

If you're starting out with EE and/or only need to do this for a few pages, I'd suggest using the pages module in the first instance, as its free, bundled with EE and requires minimal config in order to set up.

If you have a large site or a more complex URL structure with lots of nested/child pages Structure/NavEE are great choices and similarly easy to set up.
> 6 votes

# Answer
Your best bet would be to use either .htaccess, or setup an entry to use that template using the Pages Module.
> 6 votes

# Answer
create a .htaccess page in the root of your website and use this:

```
Redirect 301 /index.php/pages/faq /index.php/foo

```

alternatively, you code use EE to do the job for you:

create a template called "foo" in your default template group and put this piece of code in that template.

```
{redirect="pages/faq"}

```
> 0 votes

# Answer
Someone pointed out freeway on another question, and this seems to also do what you are asking for.
> 0 votes

---
Tags: url
---


title: NavEE active class

text:
# Question
Title: NavEE active class
EE site is using Structure and NavEE.
Is there a way without having to do a ton of if segment\_1=="this" conditionals for an active class to be set for parent level nav to be 'active' when selecting child level navs for the parents?

Right now I have working with the 'is\_selected variable when page is parent level, but for child level, that active class is active.

Hope this makes sense.

Thanks

Tad

# Answer
Check out the selected\_class\_on\_parents parameter: http://booyant.com/navee/getting-started#selected\_class\_on\_parents

That should add a class of selected on all parent items when you visit a child page.

Michael
> 4 votes

---
Tags: navee
---


# Question
Title: What is wrong with this IF/ELSE conditional?
On events pages that meet the first conditional statement (first segment is 'events' and second segment is 'not empty') the image parses as expected. However, when the first segment is 'member-directory' and the second segment is NOT '', the last conditional (if:else) is parsed.

I've tried stripping out tags and replacing them with (A,B,C) and can confirm that it is parsing the (last) if:else when second conditional seemingly should be met.

```
{exp:ifelse parse="inward"}
{if segment_1 == 'events' AND segment_2 != ''}
    {exp:ce_img:pair src="{event_masthead}" height="270" min_width="1600" max_width="1600" fallback_src="{lv_fallback_banner}" crop="yes" allow_scale_larger="yes" filter="brightness,-80|grayscale|colorize,80,39,9,10"}style="background:url('{made}') no-repeat 50% 0; height: 270px;"
    {/exp:ce_img:pair}
{if:elseif segment_1 == 'member-directory' AND segment_2 != ''}
    {member_photo_gallery limit="1"}
        {exp:ce_img:pair src="{url}" height="270" min_width="1600" max_width="1600" crop="yes" fallback_src="{lv_fallback_banner}" allow_scale_larger="yes" filter="brightness,-80|grayscale|colorize,80,39,9,10"}style="background:url('{made}') no-repeat 50% 0; height: 270px width: 1600px;"
        {/exp:ce_img:pair}
    {/member_photo_gallery}
{if:else}
    {exp:ce_img:pair src="{masthead}" height="270" min_width="1600" max_width="1600" fallback_src="{lv_fallback_banner}" crop="yes" allow_scale_larger="yes" filter="brightness,-80|grayscale|colorize,80,39,9,10"}style="background:url('{made}') no-repeat 50% 0; height: 270px;"
    {/exp:ce_img:pair}
{/if}
{/exp:ifelse}

```

Here is my fallback test that is showing that the second conditional is not being met.

```
{exp:ifelse parse="inward"}
{if segment_1 == 'events' AND segment_2 != ''}
        A
{if:elseif segment_1 == 'member-directory' AND segment_2 != ''}
        B
{if:else}
        C
{/if}
{/exp:ifelse}

```

This works. I am wondering why Croxtons doesn't. I am using the latest version.

```
{if segment_1 == 'member-directory' AND segment_2 != ''}
    {member_photo_gallery limit="1"}
        {exp:ce_img:pair src="{url}" height="270" min_width="1600" max_width="1600" crop="yes" fallback_src="{lv_fallback_banner}" allow_scale_larger="yes" filter="brightness,-80|grayscale|colorize,80,39,9,10"}style="background:url('{made}') no-repeat 50% 0; height: 270px; width: 1600px;"
        {/exp:ce_img:pair}
    {/member_photo_gallery}
{/if}

```

The snippet is used like so:

```
{!-- Masthead --}
{exp:stash:set name="masthead" parse_tags="yes"}
{snippet:masthead_background_image}
{/exp:stash:set}
{!-- /Masthead --}

```

# Answer
It seems that "parse\_tags="yes" on the {exp:stash:set} was causing the issue. Seeing that I wanted the tags inside to be parsed, but when I removed it the conditional came back as expected and images parsed.
> 3 votes

# Answer
I've fired up your reduced test case in an otherwise empty site index template and it works fine for me:

```
{exp:ifelse parse="inward"}
  {if segment_1 == 'events' AND segment_2 != ''}
        A
  {if:elseif segment_1 == 'member-directory' AND segment_2 != ''}
        B
  {if:else}
        C
  {/if}
{/exp:ifelse}

```

ie I get the following results:

/ = C
/events = C
/events/foo = A
/member-directory = C
/member-directory/foo = B

Is that as desired?

Is there anything else going on in the template that could be relevant?
> 2 votes

---
Tags: conditionals, ifelse
---


# Question
Title: How to use a common template for all pages?
Is it possible to define some container template that might contain my `<html>` declaration, then inside it it'll just embed other templates depending on the page? Right now, I'm having to declare my `<html>` tags in every page, which is not good. I want something like this:

```
// main template
<html>
    {embed="common/.head"}
    <body>
         {embed="common/.header"}

         // TODO: put some logic here to decide what to embed

         {embed="common/.footer"}
         {embed="common/.scripts"}
    </body>
</html>

```

# Answer
> 18 votes
Well, my first question would be, why don't you have that `<html>` tag in your common/.head embed? Why is it separate?

If you wish to have a template master page, take a look at the following links:

http://johndwells.com/blog/homegrown-plugin-to-create-template-partials-for-expressionengine

http://eeinsider.com/articles/template-partials-using-stash/

As with anything in EE, there are many ways to tackle this, however, i'm confident that after taking a look at those links, you should be able to decide on the right approach for you :)

# Answer
> 3 votes
As you can see there are TONS of different ways to build with ExpressionEngine. I typically setup {embed}s like others said. I shy away from using snippets but I have built sites with snippets for my doc\_head, doc\_end and the like. You're better off creating a template for each of your pages as it gives you a LOT more flexibility down the road if something changes or you want to do more with a particular page. True it's not a big deal to pull that page out of that particular template, but I try to build for flexibility. IF you build each project with that in mind you'll be in great shape.

# Answer
> 2 votes
In my projects over the past few years I've used conditionals more extensively to reduce the number of templates I was using in a project.

For speed of processing, I've done this with a combination of if-else statements and using the plugin Switchee to allow switch/case control structures. I also try to use Snippets, rather than Embeds, because Embeds involve more processing (though there are specific circumstances in which you're almost forced to use Embeds).

Based on the wording of your question, I'm not sure if reducing your templates down to a *single* common template is what you're after. If you want to do this, in theory it's possible to chop the number down to just a single common template that's loaded up with conditionals. In practice I think it's better to reduce a project to a small, manageable number of templates that do distinct things, or display data distinct ways (e.g. at least one for a listing of a channel's entries, and one for an entry's details).

# Answer
> 1 votes
Personally I would shy away from using embeds to store content that you'll need to access across multiple pages (unless you need to pass a variable). The problem with embeds is they are a single database call for each embed template you reference in the page. If you have five embeds, that's five round-trips to the database. Snippets and global variables are loaded with one call at the beginning of every request. If you don't need to pass variables, then you snippets/global variables are ideal.

A solution I've started to use is utilizing SnippetSync which allows me to save snippets and global variables as files. This allows for easy editing and version control without sacrificing performance.

So your main template will look like this:

Header Snippet - site\_header.html :

```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Site</title>
...
</head>
<body>
<!-- end site_header -->

```

Footer Snippet - site\_footer.html :

```
<!-- start site_footer -->
</body>
</html>

```

Main Template:

```
{site_header}
<!--my content -->
 ...
<!--/my content -->
{site_footer}

```

EE's User Guide has a good run-down on Snippets and how they're different than Global Variables & Embeds.

# Answer
> 0 votes
Yes, that's entirely possible by using embeds:

**Header Template**

```
<html>
    <head>
    ...
    </head>
    <body>
       // header & menu can go here..

```

**Footer Template**

```
       // footer & scripts can go here..
    </body>
</html>

```

**Main Template**

```
{embed="common/header"}
    // content goes here
{embed="common/footer"}

```

# Answer
> 0 votes
Depending on how complicated the content you are still deciding about is, the Pages Module might also do what you want.

# Answer
> 0 votes
One of my favortite ways of building templates is to pass variables in the embeds

```
// main template
<html>
    {embed="common/.head" {exp:channel:entries  limit="1"  rdf="off"} page_title="{title}"  meta-description="{summary}" meta-keywords="{title}"{/exp:channel:entries}}
    <body>
         {embed="common/.header"}

         // TODO: put some logic here to decide what to embed

         {embed="common/.footer"}
         {embed="common/.scripts"}
    </body>
</html>

```

# Answer
> 0 votes
Quite frankly all the native approaches feel completely bonkers when you compare them to the elegance of using Stash or any of its predecessors (LG Replace/NSM Transplant/String/MX Jumper).

Use Stash.

---
Tags: templates
---


# Question
Title: tracking site searches in google analytics
In google analytics, you can track site searches by setting the query parameter. EE does not have search result URLs with a query parameter in them though i.e. search result URLs look like http://mysite.com/search/270ab420bad324607c6286bf28767910/ instead of http://mysite.com/search?q=keyword

So is there an easy way to track site searches using the native EE search module in google analytics - either natively (ideally) or using an add-on? I want to keep using the native EE search module if at all possible.

From searching I've seen various code snippets altering the \_gaq.push(\['\_trackPageview' line in the analytics code, but I'm not sure exactly how to implement this and would rather not mess up the main site tracking, so I was hoping someone may have some working code for this.

Many thanks for your time.

# Answer
> 19 votes
I have a comment in the Search module docs on this. Inside your Analytics tracking code block, you can do something like this (change the segment conditionals to match your specific case)

```
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-X']);
_gaq.push(['_trackPageview']{if segment_1 == 'search' && segment_2 == 'results'}, ['/search/results/?q={exp:search:keywords}']{/if});

```

# Answer
> 4 votes
**"Super search"** supports human-readable ( and therefor analytics-friendly ) queries: http://www.solspace.com/docs/addon/c/Super\_Search

# Answer
> 3 votes
This is possible, but you need to modify the GA tracking code on EE's search results template.

There is a wiki article on how to do this, but with the launch of the new Ellis Lab site you'll have have to take a look at Google's cached version.

read the cached wiki article

**UPDATE:** Here's a link to a Gist of the same article in case the wiki doesn't make it back online

# Answer
> 1 votes
EE does have native search keyword logging. Here's a link to the info in the docs.

---
Tags: search, analytics
---


title: Addon database interaction

text:
# Question
Title: Addon database interaction
When creating Addons should we utilise the underlying database structure provided by ExpressionEngine for storing large numbers of items / information. For instance use channel entries? Or should you keep it all separate and craft your own tables / relationships etc?

If I were to take a stab at answering this myself, I'd probably say use as much of existing expressionengine tables infrastructure as possible as there isn't any great reason to re-invent the wheel. My only concern is how you might limit access to say channel entries (if you've used them) for your addon. Say if you want the user to edit information in a particular way (and it's not the standard EE way of doing it). Or is this the problem, should they be doing it the EE Way?

Is it / should it be handled differently if it's a custom Addon for one site you are working on, as apposed to creating a commercial addon?

# Answer
> 8 votes
My opinion is that it very much depends on the add-on. Something like Carthrob, for instance, lends itself perfectly to using the native channel entries table as data can be accessed using the channel entries tag and edited in the CP in the usual way. So in this instance, there is no need to re-invent the wheel.

If the structure of the data you need to store doesn't lend itself to a channel entry format, you are better off creating your own tables.

Hope this helps, Joe

# Answer
> 6 votes
My take: if this is a bespoke add-on for private use, only use `exp_channel_entries` and `exp_channel_data` if the data you're storing can added/edited using the standard EE publish/edit screens and follows the conventions of those tables (matching `entry_id` and `channel_id`, etc). Otherwise you're setting up any future developer for a whole lot of confusion, and you may get unpredictable results from third party add-ons which interact with channel data.

If it's an add-on you intend to distribute, definitely use your own database tables, no question.

Generally-speaking, the only data an add-on should be storing in default EE tables is its extension settings in the `settings` column of its `exp_extensions` row (if applicable).

# Answer
> 3 votes
General rules of thumb:

1. If you find yourself altering tables (adding columns for example) your add-on should create its own table instead.
2. If you can fit your data in core tables, by all means, do so (if you're creating new entries or editing them, for example)
3. Use your own tables within the same database for things like configuration data, and business-logic (For example an SEO module should have its own table to save title and description tag info per entry, and a config table for storing user configuration such as robots.txt value)

---
Tags: add-on-development, database
---


# Question
Title: Exp-Resso Store Shipping Rates & Calculator
We're integrating exp-resso store with a new e-commerce site. Ideally, we want to be very clear about the shipping charges for an order on the cart page before we have a lot of information from the customer (where they live, for example). I understand that some of this is required to determine the rate. With other e-commerce packages we've worked with there is a Shipping Calculator feature which prompts the visitor for their city, state, and zip and then presents them with the shipping rates that apply to their order. Can we do this with exp-resso store?

# Answer
> 8 votes
The easiest way to do this would be to have the following in your template somewhere for the default shipping plugin:

```
{exp:store:checkout}
<label>Shipping Country</label>
{field:shipping_country}

<label>Shipping State</label>
{field:shipping_region}

<input type="submit" name="update_cart" value="Update Shipping" class="btn" />
{/exp:store:checkout}

```

You would want to change that to:

```
{exp:store:checkout}
<label>Shipping Country</label>
{field:shipping_country}

<label>Shipping Zip</label>
{field:shipping_postcode}

<input type="submit" name="update_cart" value="Update Shipping" class="btn" />
{/exp:store:checkout}

```

If you are using FedEx/USPS/UPS plugins.

There are a few things to mention though so you don't get weird behavior. In the Store \>\> Settings \>\> Genereal page you will want to make sure that the "Default Shipping Address" field is set to either "None" or "Billing Address same as Shipping" if you have "Shipping Address same as Billing" you will need to change the fields to `{field:billing_country}, {field:billing_region}, and {field:billing_postcode}` respectively so that Store will calculate your shipping cost.

# Answer
> 8 votes
This shouldn't be hard to set up on your end, I'm sure there isn't code offhand to send you.

I'd set up the form prompting for city, state, and zip on my Cart page... then submit form using ajax to get the data into the session, then call a template which contains your shipping code using ajax into your page.

---

**EDIT**

Use the {exp:store:checkout} on your cart page to collect your shipping city, state and zip data. https://exp-resso.com/docs/store/tags/checkout.html

Submit that form using ajax.

In the second template, use the same {exp:store:checkout} tag to display the available shipping methods: https://exp-resso.com/docs/store/tags/checkout.html#shipping-methods

You will return this template's data with ajax after the first form is submitted.

If you don't want to use ajax, just return the form to the same page and show the shipping methods as needed.

---
Tags: expresso-store, ecommerce
---


# Question
Title: Login page returns to the login page, doesn't log me in?
I have a site being added to that is currently on 2.1.3 and cannot be updated for the time being.

All is running fine on localhost but when I try to login to the CP on the dev server the login page returns me to the login page? There are no errors on the page and credentials entered have been removed.

I have,

1. Cleared all cookies on both the dev server and the local.
2. Created a new account and imported the db to dev in case there was any corruption/clash.

# Answer
Ok, this was solved by using a combination of the replies from @mediagirl and @andiefairlie, neither were quite there but they led me to the solution.

NOTE: I didn't state in the question that I am using https://github.com/focuslabllc/ee-master-config for this set up.

The issue was that the login was setting the cookies' domain to the original site (a production site that has been cloned), so `.original-site.com`

On local this didn't cause an issue as the site was set at `local.original-site.com` and the domain was correct. In contrast when it is on the dev server it is `original-site.my-dev-server.com` and the cookie domain is now an issue.

To resolve this I added the following to the **config/config.dev.php**

```
$env_config['cookie_domain']   = 'my-dev-server.com';

```

and all was well.

I am unsure if this tied to EE v2.1.3 or a weirdness in this particular install, as I do not run into this on later versions. (I am not the original dev) Your mileage may vary of course.
> 8 votes

# Answer
Try adding this to your config.php file:

```
$config['cookie_domain'] = "";
$config['cookie_path'] = "";
$config['cookie_prefix'] = "";
$config['admin_session_type'] = "s";
$config['user_session_type'] = "c";
$config['require_ip_for_login'] = "n";
$config['require_ip_for_posting'] = "n";
$config['secure_forms'] = "n";

```
> 5 votes

# Answer
This has happened to me before where I was accessing www. but the site was setup to http:// (note: no www.\*).

Could this be the case in your scenario?
> 3 votes

# Answer
This sometimes happens on Chrome. One trick that works for me:

1. Login with FireFox or Opera
2. Go to Admin \> Security & Sessions
3. Change the cookies settings to "Cookies Only" (default is cookies & sessions)
4. Try logging in with Chrome, but with the "Auto log-in" button checked

Your issue may be something completely different, but at least on Chrome the above trick has served me well.
> 1 votes

---
Tags: login
---


title: EE Code within channel entries

text:
# Question
Title: EE Code within channel entries
Is it at all possible to have a text input or area field in which we could enter EE code to be processed by the template.

For example, if we could have a text area called "Advanced Functionality" and within this write things like

```
 {sn_contact-form}

```

Right in the channel entry, and then in our template call...

```
{advanced_functionality}

```

then that could be valuable in some instances.

Is this too far down the parse order to happen? Or does anybody know of a solution?

# Answer
You could do this combining Stash and the allow\_eecode plugin. http://www.tyssendesign.com.au/articles/cms/more-stash-examples/ has a great example of the functionality you're trying to achieve (example 1 wp shortcode).

For stash see https://github.com/croxton/Stash, allow\_eecode http://devot-ee.com/add-ons/allow-ee-code
> 5 votes

# Answer
Stash, yet again(!), is the answer:

```
{exp:channel:entries}
    {exp:stash:parse process="end"}
        {advanced_functionality}
    {/exp:stash:parse}
{/exp:channel:entries}

```

... this does the trick for parsing snippets

Then if you want to get more creative with custom shortcodes instead of snippets, you'd use stash:set first like this:

```
{exp:stash:set name="shortcode_inside_field" type="snippet"}
    <p>Hi there! It's important to set type="snippet" so that {shortcode_inside_field} will get automatically replaced with this sentence by the stash:parse tag later on.</p>
    ... now run all kinds of complicated EE tags here to generate the content of the shortcode (be sure to add parse_tags="yes") ....
{/exp:stash:set}

{exp:channel:entries}
    {exp:stash:parse process="end"}
        {advanced_functionality}
    {/exp:stash:parse}
{/exp:channel:entries}

```
> 5 votes

# Answer
I have a new module called Shortcode coming out soon which enables this type of thing. It is a bit more restrictive in that it only allows tags that have been setup for it to be parsed since it'd be very unsafe to allow for open ended template code to be entered as content. That said, it's trivial to add new Shortcodes to the module with just a few lines of code.

For instance, you could easily insert a ProForm form using this tag:

```
[form form_name="application_form"]

```

Let me know if you'd like a demo by posting in the Shortcode forum.
> 4 votes

# Answer
Hmm, good question. I dont think this would be possible with snippets, as they are always parsed too early.

By the sounds of things this is basically what the Shortcodes addon will offer - though that isn't publicly available yet - maybe @IsaacRaway can chip in and let us know?
> 0 votes

---
Tags: templates, channel, parsing
---


# Question
Title: Problem with phpstringfun and substr_count function
I'm using phpstringfun plugin to check a comma-delimited list for the presence of a single number.

```
{exp:phpstringfun function="substr_count" par1="{member_group}"}
{member-groups}
{/exp:phpstringfun}

```

member\_group is the member group of the current user. member-groups is a category custom field. I've confirmed they're both working with

```
 member-groups: {member-groups} member_group = {member_group}<br>

```

For example, I'll see the values "6,7" and "6", so 6 should be found in list. When I run the function, it always returns 0.

I've tried @dom-stubbs

```
{exp:channel:categories category_group="1" channel="pm" style="linear"}

{exp:switchee variable="{member_group}" parse="inward"}
  member-groups is: {member-groups}
  {case value="{member-groups}"}
    We have a match.
  {/case}
{/exp:switchee}

{/exp:channel:categories}

```

And no luck. I've confirmed that the member-groups and member\_group variables are available. Nothing is output.

# Answer
Although I'm unfamiliar with that plugin I doubt it's the best tool for this particular job. By the look of it that's essentially a wrapper for substr\_count which is not going to work reliably in this context. For example, if your haystack was '243,423' and your needle was '2' the function would return 2, because the string contains two instances of the character '2'. Which is useless.

What you really want to do is check a value against an array. I'd suggest using Switchee. Assuming you can format `{member-groups}` as a pipe-delimited string (e.g. `8|241|33`) you could do something like this:

```
{exp:switchee variable="global:member_group" parse="inward"}
    {case value="{member-groups}"}
        We have a match!
    {/case}
{/exp:switchee}

```

**Update:** Having more closely replicated what you're trying to do I've realised that `{member_group}` is a late-parsed variable which means that Switchee does not have access to it (i.e. it receives the raw variable name every time). That's why you weren't getting any matches.

Fortunately Mark's Switchee developer branch has support for late-parsed global vars so there's a simple solution. Install that if you haven't already and change `variable="{member_group}"` to `variable="global:member_group"`. I've updated my sample code accordingly.
> 3 votes

# Answer
Not sure of the underlying cause but a similar issue was reported in the comments for phpstringfun which remains unanswered: http://engaging.net/docs/phpstringfun#comment28

As others have advised I would look for another solution. You don't need to convert the {member-groups} field to be pipe-delimited to use switchee as you can set a case conditional to use regular expressions - see the sample code on devout:ee: http://devot-ee.com/add-ons/switchee
> 3 votes

# Answer
I'm wondering if it being across multiple lines is making a difference. Does it work correctly if formatted as...

```
{exp:phpstringfun function="substr_count" par1="{member_group}"}{member-groups}{/exp:phpstringfun}

```

Instead?
> 0 votes

---
Tags: php, phpstringfun, plugin
---


title: Grant cloning extension for a user

text:
# Question
Title: Grant cloning extension for a user
I am using the Cloner extension with EE 1.7, and I can't work out how to give one of my users access to duplicate and clone an entry.

I know I can do this as a superadmin, but I'm not sure whether I can grant access to a content contributor. Is this possible?

**NB** I'm currently using EE 1.7 (Yes, I know this is outdated).

# Answer
Have you restricted which sections of the Control Panel the other User Group can access? If so, this is probably what's causing the issue. It's been awhile, but there is at least the "Can access MODULES page" permission, which you may need to enable.

I've mirrored the EE 1.x docs here for reference since they have been taken offline. The Groups page is here.
> 1 votes

---
Tags: ee1
---


title: Plugin: allow_eecode - needed or not?

text:
# Question
Title: Plugin: allow_eecode - needed or not?
Has the ability to use and parse `{exp}` tags within custom fields been absorbed into the EE system proper, or is the Allow EE Code plugin still needed to do this?

If it's still needed, might you be able to point to where it is? EL appears to have moved the download page.

# Answer
Nope - it's still an add-on. You can find it on github.
> 7 votes

---
Tags: add-on, plugin, allow-eecode
---


# Question
Title: Update 1.6.9 to 2.5.2 Truncated content after commas/apostrophe
I'm in the middle of updating an EE 1.6.9 site to 2.5.2. Everything went smoothly up until I verified the content. For some reason any time there's a comma and/or an apostrophe the channel data and categories are all truncated from that point.

I've tried to research this as best I could but it's been tough to figure out. Has anyone else ran into this?

# Answer
> 5 votes
You may want to consider updating to the latest 1.x branch (1.7.3) before upgrading to 2.x. That's solved all issues for me in the past.

---
Tags: update
---


title: Ajax pre-populate

text:
# Question
Title: Ajax pre-populate
Whilst not really an EE specific question, I have need to present the user with a Freeform and have them type in their unique ID# which relates to another channel full of "companies" but I'd like to be able to query the number they type in, match it against a "companies" unique ID and pre populate the rest of the fields.

I know their is no single answer but any guides anyone can offer would be invaluable at this point in time.I'm a bit of an ajax N00b to boot!

Recap:

* Enter 10 digit unique ID
* Query the "Companies" channel for ID
* If found, populate forms address, suburb, state etc from Company/Channel/info
* They can then get on with the remainder of the fields.

# Answer
> 4 votes
It would be difficult to lay out the full code here, but we do something similar, so let me try to point you in the right direction.

What you are looking for is normally referred to as "jQuery Autocomplete". A great example can be found here:

http://www.ramirezcobos.com/labs/autocomplete-for-jquery-js/

Or use jQuery along with jQuery UI with this: http://jqueryui.com/autocomplete/

The first plugin will get you most of the way there, but it does require some jQuery & PHP experience.

The way it works is as follows:

* install the jQuery plugin on your server
* modify the included PHP file to include a database call based on your criteria. The query would follow the logic, "Select all fields, for entries in the Company Channel, where the Custom ID field is equal to the ID passed from the search"
* the above query and settings depend on your setup, and which jQuery plugin you use.
* you add the jQuery Autocomplete code to the one specific 'search' field in your Freeform
    + when you have that working, typing in an ID will start autocompleting existing entries. You can specify in the PHP settings file which field to display in the result box.
* Clicking on a result would then reload the page, passing the results as POST variables
* you could then use the POST variable, the company ID for example, within your main channel or Freeform tags as a parameter

CAVEATS: \- PHP knowledge needed to setup the PHP code \- MySQL skills needed to build the query (very basic though) \- You must be careful regarding customer security & privacy. Are you certain that you want to make public all of the "Company" data?

Check out the link above though, to assess how comfortable you are with this type of script. If not, it is somewhat trivial for an experienced developer.

Feel free to reach out for help here if needed.

Cheers,

Ira

# Answer
> 3 votes
Something like MadeByHippo's post is a good starting point for querying the DB for the details and return the data that you need via AJAX. With channel data you would need a slightly more complex query but the basis is there.

---
Tags: forms, ajax, pre-populate
---


# Question
Title: Can new fields be hidden by default on Publish Pages?
I'm a firm believer in the single custom field group approach, but it can be irritating that, when adding a custom field to a shared custom field group, all publish layouts automatically display that custom field. Have you found any techniques/addons to solve this?

# Answer
I have used a core hack to solve this, but I am hoping to see better solutions.

Around line 1400 of system/expressionengine/libraries/api/Api\_channel\_fields.php change

```
$field_info['publish'][$insert_id] = array(
'visible'        => 'true',

```

with

```
'visible' => 'FALSE',

```
> 3 votes

# Answer
Short of writing an extension to override the default setting of making fields visible you would need to go with your core hack.

You have to think about it from the standpoint of how most users use EE under normal circumstances. Most people would create a field for a particular channel and be happy that it is now showing up in the publish section. The same goes for something like the disable parameter in the channel entries tag and similar. It makes more sense (IMO) to have an enable parameter and only enable the things that I need per tag element. The likely hood of that happening though is going to be pretty slim though if for nothing else then backwards compatibility reasons.
> 2 votes

# Answer
Indeed, very annoying and in my opinion a bug. I don't know of any way to undo this behavior.
> 0 votes

---
Tags: custom-fields, control-panel, publish-layout
---


# Question
Title: Why is this Low Variable in a snippet not parsing?
I have a snippet that I use on nearly every page of a site. I need to give the admins some control in the fallback source of an image in that snippet. Now I know there is a parse order issue here as it works fine when dropped directly into the template, I am just wondering if there is a workaround?

```
    {exp:switchee variable="{segment_1}/{segment_2}" parse="inward"}
    {case value="events/{segment_2}"}
        {exp:low_variables:parse var="lv_fallback_banner"}
            {exp:ce_img:pair src="{event_masthead}" height="270" min_width="1600" max_width="1600" fallback_src="{url}" crop="yes" allow_scale_larger="yes" filter="brightness,-80|grayscale|colorize,80,39,9,10"}style="background:url('{made}') no-repeat 50% 0; height: 270px;"
            {/exp:ce_img:pair}
        {/exp:low_variables:parse}
    {/case}
    {case value="member-directory/{segment_2}"}
        {exp:low_variables:parse var="lv_fallback_banner"}
            {member_photo_gallery limit="1"}
                {exp:ce_img:pair src="{url}" height="270" min_width="1600" max_width="1600" fallback_src="{lv_fallback_banner}" crop="yes" allow_scale_larger="yes" filter="brightness,-80|grayscale|colorize,80,39,9,10"}style="background:url('{made}') no-repeat 50% 0; height: 270px;"
                {/exp:ce_img:pair}
            {/member_photo_gallery}
        {/exp:low_variables:parse}
    {/case}
    {case default="yes"}
        {exp:low_variables:parse var="lv_fallback_banner"}
            {exp:ce_img:pair src="{masthead}" height="270" min_width="1600" max_width="1600" fallback_src="{url}" crop="yes" allow_scale_larger="yes" filter="brightness,-80|grayscale|colorize,80,39,9,10"}style="background:url('{made}') no-repeat 50% 0; height: 270px;"
            {/exp:ce_img:pair}
        {/exp:low_variables:parse}
    {/case}
{/exp:switchee}

```

# Answer
> 7 votes
The `lv_fallback_banner` is an Assets variable type, which stores the data like this: `{filedir_x}my-image.jpg`. To parse the filedir-variable, you need to use the `{exp:low_variables:single}` tag, so Assets gets called and can process it (instead of just dumping the variable content in the template).

In this case, it will always return the parsed variable content, **not** the tagdata inside the `:parse` tag, so the `ce_img` tag will be lost. To solve, use the `:single` tag inside the `ce_img` tag's parameter:

```
{exp:ce_img:pair ... fallback_src="{exp:low_variables:single var='lv_fallback_banner'}" ... parse="inward"}

```

Also make sure everything is on a single line, or EE's template parser may choke.

# Answer
> 6 votes
Your first conditional statement is an *advanced conditional* (since it includes an `AND` clause), which means that *both* of your `{preload_replace}` variables are being called every time. Since subsequent `{preload_replace}` calls for the same variable are ignored, I'd guess that you're ending up with `{event_masthead}` every time, is that right?

# Answer
> 1 votes
To follow-up on what Tyssen said: If you don't want to use a third-party plugin ( like switchee or ifelse ) you could do it with standard EE. However Tyssen's conditionals are still being considered advanced conditionals, so they won't solve your problem.

This should work though:

```
{if segment_1 == 'events'}
    {if segment_2 == ''}
        {preload_replace:group='event_'}
    {/if}
{/if}
{if segment_1 != 'events'}
    {if segment_2 != ''}
        {preload_replace:group=''}
    {if}
{/if}

```

More on conditionals: http://userguides.ellislab.com/expressionengine/templates/globals/conditionals.html

# Answer
> -1 votes
To avoid using an advanced conditional and not necessarily having to use IfElse or Switchee (both of which are great by the way), you could do this instead:

```
{if segment_1 == 'events' AND segment_2 == ''}
    {preload_replace:group='event_'}
{/if}
{if segment_1 != 'events' AND segment_2 != ''}
    {preload_replace:group=''}
{/if}

```

That's no longer an advanced conditional because there's no if:else.

---
Tags: parse-order, snippets, low-variables
---


title: Shared field group?

text:
# Question
Title: Shared field group?
Can I put all my fields into one field group and show just the fields I need on each channel's publish view? Any future issues I might run into working this way?

# Answer
Apart from performance there's also another problem:

Suppose your 1 "master field group" is being used by 4-5 channels, and you want to add one field to one of your channels, you have to add it to your master field group, **and hide it in all the publish layouts of all your channels**.

So if you use this master field group approach, you really need to have planned out your entire website structure before setting up your fields, because having to hide each field you add in 20 different channels becomes very dull, very quickly.
> 7 votes

# Answer
If you are doing content planning then I see no problems with this approach. For example, I use separate channels for each section of a web site e.g. 'About Us', 'Why use our services'. I use the same channel field group for each of these sections since they are all structured in the same way e.g. abstract, detail, useful links etc.

I use common sense to break away from using a master field group approach - for example, if my landing and internal pages for a given section of the web site have several fields that are different then I break away from the master field group approach more for the clients' experience - never good to have a bunch of fields that don't need input for some pages but do for others!

In essence, it's a common sense approach borne out from content planning.
> 4 votes

# Answer
I am a huge advocate of having a "master" field set.

You can use Publish Layout to show/hide fields, and use add-ons like Entry Layout to further customize & present separate layouts per entry within a channel.

Only have a separate field set for add-ons that truly require them, like channel-based member fields, Solspace Calendar, etc.

The performance hit on the entry form is more than compensated by truly modular templates that share same field names across channels.
> 3 votes

# Answer
You sure can but it will come with a performance hit. Hidden fields are still loaded into the HTML source of the publish page but set to display:none using CSS. If you have a lot of fields you really could slow down the load time of the control panel.
> 2 votes

---
Tags: fields, publish-layout, field-group
---