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.

Nested snippets

February 10, 2011 11:58am

Subscribe [1]
  • #1 / Feb 10, 2011 11:58am

    Stephen Rushing

    40 posts

    I found a couple related posts on this:

    http://ellislab.com/forums/viewthread/159825/
    http://ellislab.com/forums/viewthread/159825/

    I’m not able to tell if nested snippets are a supported feature yet, but the wierd thing is, I haven’t had a problem with several others until I just tried to create a new one.

    I have a snp_news_teaser snippet:

    {snp_news_date}
    <h1 class="entry-title">
            <a href="http://{path=%27news/article%27}/{url_title}" class="bookmark">{title}</a>
        </h1>
    {snp_news_credit}
    {snp_news_summary}

    That works fine for my “news” and “capital_project” channels. Although, I need to display “capital_project” entries on the “news/project” template, so I created a new snippet called snp_project_teaser, identical to the snippet above, except with the different template path.

    {snp_news_date}
    <h1 class="entry-title">
            <a href="http://{path=%27news/project%27}/{url_title}" class="bookmark">{title}</a>
     </h1>
    {snp_news_credit}
    {snp_news_summary}

    The {snp_news_teaser} renders perfectly, but the snippets in {snp_project_teaser} do not (they just show the snippet code, i.e. {snp_news_date}).

    I’ve tried clearing all cache in EE, sync’d the template file, and updated the template through the EE interface.

    Here’s the URL where this is happening: http://uptown.esiteful.com/news/projects

    And the template code calling the {snp_news_teaser} and {snp_project_teaser} snippets:

    <section class="wrap-index index-projects index-projects-current">
        {exp:channel:entries channel="capital_project" category="88"}                            
            <div class="index-item project project-{entry_id} hnews">
                {snp_admin_entry_actions}
                {snp_news_teaser}
            </div>
        {/exp:channel:entries}
    </section>
    
    
    <section class="wrap-index index-projects index-projects-current">
        <h2>Recently Completed Projects</h2>
    <p>    {exp:channel:entries channel="capital_project" category="89"}<br />
        <div class="index-item project project-{entry_id} hnews"><br />
            {snp_admin_entry_actions}<br />
            {snp_project_teaser}<br />
        </div><br />
        {/exp:channel:entries}<br />
    </section>

  • #2 / Feb 10, 2011 4:12pm

    Ingmar

    29245 posts

    I’m not able to tell if nested snippets are a supported feature yet

    I am afraid that, no, nesting snippets is not supported at this point.

  • #3 / Feb 10, 2011 4:14pm

    Stephen Rushing

    40 posts

    Can you provide some insight as to why it works on one and not the other? They are basically identical, and I’ve not had any trouble until {snp_project_teaser}.

    Snippets are expanded at a very early stage on each template, making it possible for them to hold dynamic content, ExpressionEngine tags, other variables, PHP, etc. They shine when you need to reuse dynamic information, but don’t need the extra overhead of access control or separate preferences of an embedded template.

    http://ellislab.com/expressionengine/user-guide/templates/globals/snippets.html

    I realize you could just add a qualifier to the docs like “except other snippets”, but I that definition indicates that snippets can handle any template tag. That is their benefit over global variables, and their minimal overhead and direct inclusion is their benefit over templates. Just as nesting is practically essential to templates, it is practically essential to snippets.

    Within the same template, using the same nested snippets, one snippet works, and one doesn’t. It doesn’t matter what order or container the snippets are called in, which seems more like a bug in the tag processing.

    Please let me know what we can do to track this down.

  • #4 / Feb 11, 2011 10:17am

    Ingmar

    29245 posts

    Can you provide some insight as to why it works on one and not the other?

    Sorry, no. As I’ve said, it’s not supported and generally won’t work; certainly not reliably. If I had to guess it’s got to do with the order in which snippets themselves are parsed (which we have no control over).

    ... nesting is practically essential ... to snippets.

    Feel free to make a Feature Request, please.

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

ExpressionEngine News!

#eecms, #events, #releases