31

TLDR; In general, my preference would normally be to use a snippet, unless I need the variable content to be user editable (eg site email), and to only use an embed when parse order issues or similar necessitate it. Here's why... Snippets: Snippets are frequently my first choice for implementing reusable code fragments in EE. They are parsed at a very ...


11

We use Snippet Sync (http://devot-ee.com/add-ons/snippet-sync) almost exclusively now for our repeatable snippets ... we also use Low Variables (as mentioned by aelvan, but not so much for 'snippets' but more for the content that the users need to edit infrequently. We tend to use snippets for sections of repeatable HTML/EE code (for example we may create ...


9

Try turning off javascript protection to allow the conditionals to parse: $config['protect_javascript'] = 'n'; Also, I would wrap the channel entries tag around the conditional like so: <script type="text/javascript"> ... {exp:channel:entries channel="products" disable="member_data|pagination" limit="1"} {if add_option_on=="On"} if (thisForm.os2....


8

All three of these are used for enabling you to not repeat yourself when building sites, but they vary in functionality quite a lot. Global Variables Global Variables are used generally for storing pieces of content that might not be be part of an entry, for instance a contact form email address, a store address, etc. You can not use EE tags within a global ...


7

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 ...


7

As someone who has been using EE for years, and going about templating in exactly the manner you are trying to for those many years, and who is just now learning a much easier way, I would like to suggest you look into using Stash. The difference is that in the EE templating method you are pursuing, and that I and many others used for years is that your ...


7

You can't set up Snippets, but you can set up Global Variables in your config.php file. Below is a code example from this blog post titled ExpressionEngine config.php. $default_global_vars = array( // Tag parameters - Short hand tag params 'global:disable_default' => 'disable="categories|pagination|member_data"', 'global:disable_all' ...


6

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?


6

Low Variables FTW. It combines global variables, snippets and embedding templates all into one addon that also gives you flat files for snippets and global variables. You can also easily hide some variables from the client - great for code snippets that are developer only. Finally low variables has many variable types including compatibility with wygwam, ...


6

My choose is Bjorn SnippetsSync - simple and stable


5

I use SnippetsSync (http://devot-ee.com/add-ons/snippetssync) to accomplish this on any site that doesn't use Low Variables. Note that this is not the same as the confusingly similarly-named Snippet Sync already mentioned above! This one is free, and is less configurable with no extension settings, but has always worked very well for what I wanted it to do.


5

For visibility, this is what your snippets look like: [segment_category_ids] => 241 [segment_1_category_id] => [segment_1_category_parent_id] => [segment_1_category_group_id] => [segment_1_category_name] => [segment_1_category_description] => [segment_1_category_image] => [segment_2_category_id] => [...


4

No, you can't generate them dynamically but you can use Snippet Sync or Libraree to use snippets as files and port them into other projects. I use Libraree as part of my base install with a couple base snippets for a header and footer that I carry through projects. Using config overrides (Focus Lab's Master Config) I set where to store the files and edit ...


4

They're stored in the exp_snippets database table.


4

Yes, as long as the template in which you put the snippet has PHP enabled.


4

There are plenty of plugins to mess with the parse order, but I usually try to avoid installing plugins if I can help it. The simplest solution, which works in 99% of cases, is to just use an embed. Embeds are parsed after everything else, so whenever you have an early parsing issue, just throw the problem code into an embed. It's true that embeds have ...


4

While use cases for it are rare, CSS templates can parse tags if you need them to, but you must link to them with {path='template_group/css_template'} instead of {stylesheet='template_group/css_template}.


3

That looks like expected behaviour to me. I'm assuming that you're seeing this at a URL which has a category slug in segment_3 and nowhere else, so all of the other Seg2Cat variables are empty. What was the behaviour you were expecting?


3

This is due to the parse order. EE parse snippets at a very early stage all at once, hence not being able to have a snippet within a snippet. I suggest removing the {sn-listing-pageination} and just hard code that in the {sn-listing-videos}. Or you could convert all your snippets/variables over to Low Variables and set the {sn-listing-pagination} to a ...


3

I use Low Variables when the project calls for it otherwise Libraree is part of my base isntall http://devot-ee.com/add-ons/libraree


3

I personally prefer Low Variables as it does so much more than just let you edit as files. You can control the parse order allowing you to create global variables or snippets. Plus it works with a whole bunch of field types making it extremely useful for content that clients need to edit but don't deserve a channel. And yes you can hide variables/snippets ...


3

Snippets are not intended to be used by / known by end users. They are developer tools for making your code more DRY - not so much to hold content. This is why the access to them is through the Templates area of the CP rather than the Content area. Here is one approach to allowing users to create different sidebars - note that you could use the native ...


2

The <!CDATA block is only required if you need your document to be parsable as XML, for example if you're using an `XHTML~ doctype. For a full explanation of why this was necessary in the past see this stackoverflow qn. If you're using a modern, HTML5 doctype then using <!CDATA isn't necessarily, but I'm guessing EllisLab include it in the {encode} ...


2

My suggestion would be to use Low Variables, which allows you to set parse order for your snippet effectivly letting you set it to be a global variable or a snippet. Additionally you can pass variables to a low variable as if it were an embed using preparse (unlike traditional snippets which can't have anything passed to them) - see this blog post for ...


2

did you check if your if statements are matched? something like {company_membership_package var_prefix="pkg"} {if '{pkg:title}' == 'Premium'} ppackage title is Premium {if:else} package title is not Premium {/if} {/company_membership_package} By the way, maybe using single quotes as i did might help too


2

You can fetch that global variable like: $address = ee()->db->select('variable_data')->where('variable_name', 'address')->get('global_variables')->row('variable_data'); echo trim(str_replace(array("\r\n","\n","\r"), ', ', $address)); It would work for you.


2

In your code above 'logo' is a Stash variable, not a snippet. You would need to access it like {exp:stash:get name="logo"}. You could add type="snippet" to the stash:set tag when you set the variable and then access it like so: {logo}; however I'm not sure why you don't just use the original snippet itself: {snippet:masthead_logo} ?


2

EE's CSS and JS templates do not parse variables or tags. They're just static templates. Best to avoid EE altogether and just create CSS and JS files on the server. To still be somewhat dynamic, you can always hard-code rules in the <head> (for CSS) or above </body> (for JS). For example: <style> .style { width: {snippet_width}px;...


2

First of all, the stylesheet tag needs quotation marks. {stylesheet="global_embeds/style"} If you link to the JS file using path variable, all the templates variables on the linked file will be parsed. {path="global_embeds/init.js"} But I really don't think it's good for performance. It's much better to use static links for the JS and CSS.


2

The snippets are not actually "loading" - they are simply bits of text being stored in memory (much like global variables). They aren't actually processed until they're called. So they're not an overhead problem. You'll see these being "loaded" each time you run the template engine - which means the primary template, and then each embed.


Only top voted, non community-wiki answers of a minimum length are eligible