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.

Problem with channel in snippet

March 04, 2011 12:21pm

Subscribe [5]
  • #1 / Mar 04, 2011 12:21pm

    Paul Phillips

    12 posts

    Hi,

    Having a very strange issue setting up a channel within a snippet to use as an event feed.  Here’s the snippet:

    <ul>
    {exp:channel:entries channel="events" orderby="start_date" limit="5" dynamic="no"}
    <li>
          <a href="http://{permalink}">{title}</a>
    
          <span>{start_date}</span>
    </li>
    {/exp:channel:entries}
    </ul>

    But when the snippet renders it explodes at the href:

    <ul>
    
    <li>
          < a href=
                </div>

    I moved the snippet into the template and it worked fine… what am I missing?

    BTW, had to add a space after < and before “a” to post the output.  Shouldn’t everything within a “code” block render as plain-text?  😖

  • #2 / Mar 04, 2011 6:03pm

    Sue Crocker

    26054 posts

    Welcome to the ExpressionEngine forums, Paul.

    Since you’re new to the EE forums, have you seen EEWiki:// How to Post a Support Request?

    Can you tell us which version/build of EE2.x you’re using? See EEWiki:// HowTo Determine My EE Version

  • #3 / Mar 04, 2011 6:08pm

    Paul Phillips

    12 posts

    Hi Sue,

    We’re running version 2.1.3 build 20101220.

    Thanks.

  • #4 / Mar 05, 2011 4:39pm

    Greg Salt

    3988 posts

    Hi Paul,

    I’m afraid that I can’t replicate this problem. Where was this code created? Did you code it straight into the snippet or was it copied from somewhere else?

    Cheers

    Greg

  • #5 / Mar 07, 2011 12:06pm

    Paul Phillips

    12 posts

    I coded it straight into the snippet.

    I think I’ve found the problem.  It looks like EE can’t handle passing HTML content from a snippet into an embed via parameters.  Is there any work around to this?

    In my index template:

    {embed="_includes/.block" title="Title" content="{events_block}"}

    Here’s the .block template:

    <div class="block">
       <div class="block_title">
         <h3>{embed:title}</h3>
    <p>   </div><br />
       <div class="block_content"><br />
          {embed:content}<br />
       </div><br />
    </div>

  • #6 / Mar 07, 2011 5:03pm

    Ingmar

    29245 posts

    Yes, there’s going to be issue with quotation marks. You could try single ones:

    {embed='_includes/.block' title="Title" content="{events_block}"}

    Does that work?

  • #7 / Mar 07, 2011 5:19pm

    Paul Phillips

    12 posts

    This works…

    {embed="_includes/.block" title="Title" content='{events_block}'}

    ... but ONLY if there are no single quotes (’) in my snippet. Otherwise, *BOOM* it explodes.

    Is there any permanent fix for this, or do I just need to trash the idea of passing HTML data into a template using a snippet?

  • #8 / Mar 07, 2011 5:49pm

    Ingmar

    29245 posts

    ... but ONLY if there are no single quotes (’) in my snippet.

    Yes, that’s understood.

    ...do I just need to trash the idea of passing HTML data into a template using a snippet?

    Why pass it in in the first place? Wouldn’t the snippet be available in the embed as well? It’s a global variable, after all.

  • #9 / Mar 07, 2011 7:49pm

    Paul Phillips

    12 posts

    Why pass it in in the first place? Wouldn’t the snippet be available in the embed as well? It’s a global variable, after all.

    Because the block template is reusable.  I use it like this:

    {embed='_includes/.block' title="Title 1" content="{events_block}"}
    {embed='_includes/.block' title="Title 2" content="{news_block}"}

    Surely there must be a reasonable solution for this?  How does one pass HTML content into a template?

    Do I convert my snippets to templates, or is that irrelevant?

    I suppose I could pass a token into the template so the template could “choose” which snippet to load, but that increases the complexity of the .block template and seems superfluous.

  • #10 / Mar 08, 2011 4:51am

    John Henry Donovan

    12339 posts

    Paul,

    I would have approached it this way using embeds rather than snippets

    {embed='_includes/.events_block' title="Title 1"}
    {embed='_includes/.news_block' title="Title 2"}

    or alternatively populate your channel parameters via the embed parameters

    {embed='_includes/.block' title="Title 1" channel="events" limit="5"}
    {embed='_includes/.block' title="Title 2" channel="news" limit="5"}
    <ul>
    {exp:channel:entries channel="{embed:channel}" orderby="start_date" limit="{embed:limit}" dynamic="no"}
    <li>

    Does that help or confuse 😊

  • #11 / Mar 08, 2011 12:29pm

    Paul Phillips

    12 posts

    Thanks John.

    I wanted to avoid templates due to the overhead.  The channel solution would work great if the structure of the events and news blocks weren’t so differently structured.

    *sigh*

    There’s really no way to pass HTML via a parameter? I’m at a loss for words…

  • #12 / Mar 08, 2011 5:57pm

    Barry Cogan

    291 posts

    Hi Paul,

    Snippets are not designed to work that way.  It has to do with parsing the information in the parameter stage.

    To give the example you wouldn’t type

    {embed='_includes/.block' title="Title" content="{exp:channel:entries channel="events" orderby="start_date" limit="5" dynamic="no"}.....{/exp:channel:entries}"}

    and expect that to work.  Snippets are a glorified placeholder for text which the template parser swaps in.  So, when the parsing gets done that statement would break horribly.

    John Henry’s solution is perfect for what you are trying to do and actually saves you a snippet too! 😊  with the one embed you can have events and news both work for you.

    Best regards,
    Barry

  • #13 / Mar 08, 2011 6:11pm

    Paul Phillips

    12 posts

    Thanks for the insight into the background functionality, Barry.

    On the plus side I guess it’s cool I can build EE markup using snippets. 😊

    I’ll avoid snippets for user generated content and stick with embeds.

    Thanks again.

  • #14 / Mar 08, 2011 6:16pm

    Barry Cogan

    291 posts

    No worries at all Paul!  Using embeds for that purpose is a much better way to go 😊

    Pleas do not hesitate to post again with any future issues!

    Best regards,
    Barry

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

ExpressionEngine News!

#eecms, #events, #releases