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.

Set preload_replace to a variable within a channel:entries tag

September 07, 2010 8:58pm

Subscribe [2]
  • #1 / Sep 07, 2010 8:58pm

    ryarwood

    7 posts

    This bit of code below does not work. If I use the actually community slug manually (ie: “capistrano-pointe”) then the preload_replace does it’s job.

    {exp:channel:entries channel="floor-plans" limit="1"}
        {preload_replace:global-slugginsons="{community-slug}"}
    {/exp:channel:entries}
    
    {exp:channel:entries channel="communities" url_title="{global-slugginsons}" limit="1" dynamic="no"}
    
    <!-- LOTS OF FUN TEMPLATE STUFF -->
    
    {/exp:channel:entries}

    I want to run a loop at the top to set a variable {global-slugginsons} to be the {community-slug}. Through a bit of trial and error I figured out preload_replace is a decent way to go (setting that manually works!), but I need it to be set to the {community-slug}. Suggestions?

  • #2 / Sep 08, 2010 6:05am

    Boyink!

    5011 posts

    Pre-load replace is what the name says, a text-replacement variable that is filled in before the rest of the template is parsed.  It’s not designed to be used in a channel:entries loop.  I always explain them as a “template constant” - not designed to be changed at “run-time"l so to speak.

    There’s probably a better way to go if you can explain at a higher level what you are trying to do.

  • #3 / Sep 08, 2010 3:23pm

    ryarwood

    7 posts

    It’s basically the same issue you helped me with on a different post. I have a channel communities that has a bunch of information about the location, welcome copy, photos (via categories). On the floorplans (separate channel) page of the site…

    http://dev.russellyarwood.com/communities/floor-plans/capistrano-pointe

    ...I need to have a way of telling the template that’s it’s still pulling data from the communities channel and which community to grab. Each community post or item (not sure what we call it in ee) has a url_id that also matches the category name. So really I just need to get the string “capistrano-pointe” into that channel loop above. I originally tried to pull it from the categories, but I forgot I also have region categories attached so it wouldn’t work. Long story short I put a community-slug variable on each floorplan that is that exact string. I have the rest of the functionality for the site sorted out, it’s just that one loop.

    Any idears?

  • #4 / Sep 08, 2010 3:33pm

    Lisa Wess

    20502 posts

    You might check out the String plugin

  • #5 / Sep 08, 2010 3:39pm

    Boyink!

    5011 posts

    Are you saying that you have a channel with an entry of a specific url-title, ie “
    “capistrano-pointe”, and that url_title is also a category_url_title for a category assigned to another channel, and you want one template to display both the entry and the category with matching url titles?

  • #6 / Sep 08, 2010 5:11pm

    ryarwood

    7 posts

    Here was my final solution on this one:

    {exp:channel:entries channel="floor-plans" limit="1"}
      {embed="includes/floorplan-header" global-slugginsons="{community-slug}"}
    {/exp:channel:entries}

    Then in floorplan-header…

    {exp:channel:entries channel="communities" url_title="{embed:global-slugginsons}" limit="1" dynamic="no"}

    That worked, I need to go into some of my other templates and try out this method. It also too 2 pointless channel tags out of the mix. Thanks everyone!

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

ExpressionEngine News!

#eecms, #events, #releases