ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

preload_replace vs snippet?

January 05, 2012 3:19am

Subscribe [3]
  • #1 / Jan 05, 2012 3:19am

    nyc

    66 posts

    I’m reading through ExpressionEngine2 A Quick Start Guide and it talks about using this:

    {preload_replace:my_blog="<a href='http://website.com/blog'>my blog</a>"}

    At the top of a template and adding {my_blog} throughout the template but I was wondering what would be the reason to use this over something like a snippet?

  • #2 / Jan 05, 2012 6:32am

    John St-Amand

    865 posts

    You could just as easily use a global variable for this.  A snippet would only be needed if you were going to be using any expression engine tags - snippets parse EE tags, whereas global variables do not.  So for a quick comparison:

    As a global variable (with no EE tags):

    my blog

    As a snippet (since it contains EE tags):

    my blog

    But the result of each is the same.  Performance-wise, the global variable might be ever so slightly faster simply because nothing inside of it needs to be parsed.

  • #3 / Jan 05, 2012 6:55am

    Boyink!

    5011 posts

    Different scope is another reason.  pre_load replace variables only hold scope for the specific template they are created in.  Snippets are global.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases