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.

Snippets and segment variables

July 25, 2011 6:39pm

Subscribe [3]
  • #1 / Jul 25, 2011 6:39pm

    timmurtaugh

    12 posts

    So, I have this little piece of code:

    {cover-{segment_2}}

    Where “cover-this” is the name of a snippet, and “this” is the value of segment 2 in the URL.

    I was sort of surprised that it worked at all, but sometimes it works, and sometimes it doesn’t. The times that it doesn’t work are usually the first time I’m hitting the page after a break, so perhaps the segment variable gets cached and purged at some point?

    Anyway, I guess my question is this: How can I call a snippet using information from the URL? Would it be better if this were a global variable?

  • #2 / Jul 25, 2011 7:22pm

    What you have to consider here is the order of which stuff is processed by expression engine. If the segment variable is processed before the snippet is loaded, then this would work. I am not sure as to why this would sometimes work and sometimes not, but I believe it’d be a lot easier for you to either load an embedded template or a global variable. If you don’t have any dynamic code in what you want to load then you should definetly go for a global variable.

    /Rasmus

  • #3 / Jul 26, 2011 11:08am

    Sue Crocker

    26054 posts

    Thanks for the assist, Rasmus.

    I’d also consider using a global variable. Will that work for you?

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

ExpressionEngine News!

#eecms, #events, #releases