whats the difference? right now I have {embed="embeds/.header} which includes everything from the !Doctype to the </head> tag but why use that instead of a global variable and putting everythign in {header} ?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
December 29, 2011 9:07pm
Subscribe [8]#1 / Dec 29, 2011 9:07pm
whats the difference? right now I have {embed="embeds/.header} which includes everything from the !Doctype to the </head> tag but why use that instead of a global variable and putting everythign in {header} ?
#2 / Dec 30, 2011 7:34am
Performance is the biggest factor. Embedded templates invoke the template parser where tools like snippets (which I recommend over global variables) do not.
Some discussion:
http://www.train-ee.com/courseware/free-tutorials/comments/snippets-or-embedded-templates/
Basically it boils down to - do I need to send a variable into the template (possibly the page title in your case)? If so then it’s an embedded template with an embed variable. If not, then I’d use a Snippet for better performance.
#3 / Dec 30, 2011 4:44pm
Performance is the biggest factor. Embedded templates invoke the template parser where tools like snippets (which I recommend over global variables) do not.
Some discussion:
http://www.train-ee.com/courseware/free-tutorials/comments/snippets-or-embedded-templates/Basically it boils down to - do I need to send a variable into the template (possibly the page title in your case)? If so then it’s an embedded template with an embed variable. If not, then I’d use a Snippet for better performance.
Thanks! Why do you recommend Snippets over Global Variables? and since you do, do you use global variables at all for anything since they both look like {variablename} ?
#4 / Dec 30, 2011 5:00pm
Snippets vs. Globals:
http://ellislab.com/expressionengine/user-guide/templates/globals/snippets.html
I’d recommend a naming schema so they can be distinct in code:
{snp_snippet_name}
{gv_variable_name}In practice I’ve found little use for Globals Variables.
#5 / Dec 30, 2011 5:05pm
Snippets vs. Globals:
http://ellislab.com/expressionengine/user-guide/templates/globals/snippets.htmlI’d recommend a naming schema so they can be distinct in code:
{snp_snippet_name} {gv_variable_name}In practice I’ve found little use for Globals Variables.
I see so I will go with snippets then.. you said you’ve found little use for globals would that be to replace very simple things like text?
#6 / Dec 30, 2011 6:23pm
The only time I’ve really used Global Variables is on multi-lingual sites for different versions of “Read more >>” links, ect.
You can’t give clients access to Global Variables or Snippets without giving them access to templates, so I don’t see them as being places to store content that I ‘d want users to change.
If the content is client-editable it goes in a Channel—and on many sites I run a “miscellaneous content” channel that exists just for that reason.
#7 / Dec 30, 2011 6:28pm
The only time I’ve really used Global Variables is on multi-lingual sites for different versions of “Read more >>” links, ect.
You can’t give clients access to Global Variables or Snippets without giving them access to templates, so I don’t see them as being places to store content that I ‘d want users to change.
If the content is client-editable it goes in a Channel—and on many sites I run a “miscellaneous content” channel that exists just for that reason.
Ok thanks! that seems pretty useful to use htem in that way
#8 / Jan 11, 2012 1:24am
Thanks - these posts made a lot of sense to me.
#9 / Jan 30, 2012 12:22pm
Hi folks,
I noticed this thread might have something to do with what I’m currently trying to achieve.
I’ve had a fairly standard site built for me in EE. Content is in channels, structure is in templates, snippets and stylesheets. Global variables aren’t used at all.
However, currently there’s a header menu, which basically sits at the top of page, is common amongst site pages and displays links to enable users to navigate through.
Currently, that menu is implemented in a snippet, which uses an unordered list to present the menu options. The options are currently plain text hyperlinks.
I would like to add a bit of colour and ‘pizazz’ to the site - by using images in place of the plain text. I’m trying to use an {if} .. {if:else} .. {/if} statement to display the appropriate image based on segment. The idea being that one colour of image is used for inactive pages and an opposing colour of image is used for the page the user is currently looking at.
But based on my trial and error, I suspect the snippet has no awareness of what segment is being displayed. Is there a way to achieve this using the segment variable and snippets or must I use a global variable, eg {gv_page_name}?
#10 / Jan 30, 2012 12:31pm
Snippets should have access to segment variables.
Did you try just returning them to the screen? It might have been a formatting issue with your conditional.
#11 / Jan 30, 2012 12:39pm
Thanks for the quick response, though not quite sure what you mean by ‘returning them to the screen.’
My conditional looks something like this:
{if segment_3=="home"}URL/home-high.gif{if:else}URL/home-low.gif{/if}
It’s contained within a template as follows -
<body>
<div id=“all”>
<!—menu—>
<div id=“menu”>
{snp_main_menu}
</div>
<!—end menu—>
...
Thoughts?
#12 / Jan 30, 2012 1:01pm
When you need to check the content of a segment variable just put it somewhere in the code where it will render to the screen.
Does your url have ‘home’ in it?
#13 / Jan 30, 2012 1:14pm
Yes I think that is the problem.
I’ve re-typed and it now works for all the other list items. They all have a segment after the {site_url}.
The only one it doesn’t work for is the homepage, as there’s nothing after {site_url} - it just uses the main/home template.
For that page, would I just do a comparison against {site_url} in my conditional?
Thanks very much for your help.
#14 / Jan 30, 2012 1:19pm
Just do:
{if segment_1==""}#15 / Jan 30, 2012 5:10pm
I need to get better at using snippet. Unfortunately I work on a PC at work and so Mountee’s Snippets as files method doesn’t work. I think that’s currently the biggest flaw in snippets and hopefully future EE’s fix this.