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.

multi-select and embed templates

February 16, 2012 11:40am

Subscribe [3]
  • #1 / Feb 16, 2012 11:40am

    matrixgroup

    15 posts

    I have a multi-select field in one of my channels named optional_widgets which I want to use in order to display additional widgets on my page.

    I am currently using the following code in my display

    {exp:channel:entries status="{open_statuses}"}
     {optional_widgets}
      {if "{item}" =="Events"}
       {embed="widgets/calendar"}
      {/if}
      
      {if "{item}" == "eUpdate"}
       {embed="widgets/eupdate"}
      {/if}
      
      {if "{item}" == "Testimony"}
       {embed="widgets/testimony"}
      {/if}
     
      {if "{item}" == "Subscription"}
       {embed="widgets/subscription"}
      {/if}
     {/optional_widgets}
    {/exp:channel:entries}

    The if statements are working, but instead of seeing the embeded template, I see the text

    {embed="widgets/subscription"}

    I’ve even tried simplifying the code to be

    {exp:channel:entries status="{open_statuses}"}
     {optional_widgets}
      {embed="widgets/subscription"}
     {/optional_widgets}
    {/exp:channel:entries}

    Which results in the same output.

    The only way I can get the {embed} to works is by placing it outside the {optional_widgets} tags. This then defeats the purpose of giving the content admins the ability to enable or disable these widgets.

    I need help in figuring out how to get this functionality working.

  • #2 / Feb 17, 2012 1:56pm

    Shane Eckert

    7174 posts

    Hello matrixgroup,

    I am sorry to hear you are running into this snag.

    I am not familiar with tag pair I see in your example.

    {optional_widgets} {/optional_widgets}

    Can you tell me where these come from?

    [EDIT] I understand now what you are trying to do now. I will add more to the thread.

    Thank you,

  • #3 / Feb 17, 2012 3:31pm

    matrixgroup

    15 posts

    That tag pair is from the multi-select custom field I created.

    I spent a little more time playing around with this. The biggest change is that attempted to change the custom field from multi-select to checkbox. It appears that the checkbox has the same issues.

    I’ve created a temporary work around where I added a “display: none;” style to the div containing each widget. I then generate the javascript to show the widgets I want inside the {optional_widgets}{/optional_widgets} tag.

    I would still prefer to do this with just the embed tags.

    Is the fact that {embed} doesn’t work within a checkbox/multiselect tag pair a bug or is this by design?

  • #4 / Feb 17, 2012 3:44pm

    Ian Young

    200 posts

    Are you sure that your conditional statements are working correctly? Instead of trying to output the embed just try testing with a plaintext output and maybe include {item} in each conditional to see what value is returned.

    Also I don’t think you should be enclosing {item} in brackets. It’s a tag which needs processing rather than a literal value. Remove those and see what you get.

  • #5 / Feb 17, 2012 5:45pm

    Shane Eckert

    7174 posts

    Hi matrixgroup,

    I talked with a fellow Customer Advocate and this really looks like a case of proper Parse Order.

    If you change simple conditionals to advanced conditionals that would be one way to get the parse order to work in your favor.

    Anything beyond the basic {if x=y} is considered advanced.

    So you can even use {if:elseif} {if:else} to make it advanced.

    {exp:channel:entries status="{open_statuses}"}
     {optional_widgets}
      {if "{item}" =="Events"}
       {embed="widgets/calendar"}
      {if:elseif "{item}" == "eUpdate"}
       {embed="widgets/eupdate"}
      {if:elseif "{item}" == "Testimony"}
       {embed="widgets/testimony"}
      {if:else "{item}" == "Subscription"}
       {embed="widgets/subscription"}
      {/if}
     {/optional_widgets}
    {/exp:channel:entries}


    Does that make sense?

    Let me know if you need clarification or have any more questions.

    Cheers,

  • #6 / Feb 21, 2012 11:38am

    matrixgroup

    15 posts

    Hi Shane,

    I took a look, and attempted to implement your code. When using the advanced conditionals I still see ‘{embed="widgets/calendar"}’ being displayed without the .

    My code is now:

    {exp:channel:entries status="{open_statuses}"}
     {optional_widgets}
      {if "{item}" =="Events"}
       {embed="widgets/calendar"}
      {if:elseif "{item}" == "eUpdate"}
       {embed="widgets/eupdate"}
      {if:elseif "{item}" == "Testimony"}
       {embed="widgets/testimony"}
      {if:elseif "{item}" == "Subscription"}
       {embed="widgets/subscription"}
      {/if}
     {/optional_widgets}
    {/exp:channel:entries}
  • #7 / Feb 24, 2012 12:04pm

    Shane Eckert

    7174 posts

    Hello matrixgroup,

    Can you tell me where this code resides? Is it in an embedded template or a snippet?

    Can you show me the entire contents of the template?

    Cheers,

  • #8 / Feb 24, 2012 2:03pm

    matrixgroup

    15 posts

    The code is in an embeded template. The full template looks like

    </div>
    </div>
    
    
    <div class="col three sidebar">
    
    {embed="includes/default_sidebar"}
    {exp:channel:entries status="{open_statuses}|pending"}
    
    {if extended}<div class="related">{extended}</div>{/if}
    
    {if default_widgets != "Remove"}
     
     {optional_widgets}
      {if "{item}" =="Events"}
       {embed="widgets/calendar"}
      {if:elseif "{item}" == "eUpdate"}
       {embed="widgets/eupdate"}
      {if:elseif "{item}" == "Testimony"}
       {embed="widgets/testimony"}
      {if:elseif "{item}" == "Subscription"}
       {embed="widgets/subscription"}
      {/if}
     {/optional_widgets}
    
    {/if}
    
    {/exp:channel:entries}
    </div>
    
    </div>
    <!-- end .content_inner-->
    
    </div>
    <!--- end #content --->
    
    {embed="includes/footer_links"}
    
    <div id="footer">
    <div class="sisters"><a href="http://www.rocketcontest.org/target=_blank" rel="noopener">/images/icons/tarc_footer.gif</a><a href="http://www.NationalAerospaceWeek.org/" target="_blank" rel="noopener">/images/icons/naw_footer.gif</a><a href="http://www.LaunchintoAerospace.org/" target="_blank" rel="noopener">/images/icons/launch_footer.jpg</a><a href="http://secondtonone.org/" target="_blank" rel="noopener">/assets/second-to-none-logo.png</a></div> 
    
    Copyright © <?php echo date('Y'); ?> Aerospace Industries Association. All Rights Reserved.
    1000 Wilson Boulevard, Suite 1700, Arlington, VA, 22209
    <a href="http://{my_site}terms_conditions/">Terms and Conditions</a>
    <a href="http://{my_site}privacy_statement">Privacy Policy</a>
    <a href="http://{my_site}contact_us/">Contact us</a></div>
    <!--- end #footer --->
    
    </div>
    <!--- end #wrapper --->
    
    
    </body>
    
    
    </html>
  • #9 / Feb 25, 2012 11:03pm

    Dan Decker

    7338 posts

    Hi matrixgroup,

    Ok, lets get this out of the embed for a moment. Make a new template and place just this code in it:

    {exp:channel:entries status="{open_statuses}|pending"}
    
    {if extended}<div class="related">{extended}</div>{/if}
    
    {if default_widgets != "Remove"}
     
     {optional_widgets}
      {if "{item}" =="Events"}
       {embed="widgets/calendar"}
      {if:elseif "{item}" == "eUpdate"}
       {embed="widgets/eupdate"}
      {if:elseif "{item}" == "Testimony"}
       {embed="widgets/testimony"}
      {if:elseif "{item}" == "Subscription"}
       {embed="widgets/subscription"}
      {/if}
     {/optional_widgets}
    
    {/if}
    
    {/exp:channel:entries}

    What is the result of having that in it’s own template?

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases