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.

emebed content {assign_variable:my_weblog="my_weblog"}

June 15, 2010 7:49am

Subscribe [3]
  • #1 / Jun 15, 2010 7:49am

    Mobster

    64 posts

    I am a big fan of splitting my sites into individual elements for updating purposes.  In other CMS’s I used php includes for everything. 

    Why, when embedding included content in EE, do I need to include:

    {assign_variable:my_weblog="my_weblog"}

    into every embedded item for EE tags to work? 

    Once included in the header, shouldn’t that pretty much cover all embedded content?

    Sorry, I’m slowly, and I mean slowly learning EE.

    Thanks!

    Update: Ok, I found this http://expressionengine.com/knowledge_base/article/embedded_templates_not_using_my_assigned_variables/

  • #2 / Jun 15, 2010 11:50am

    Focus Lab Dev Team

    1129 posts

    You can pass variables to embeds which might be just what you’re looking for.

    {embed="site/header" variable_name="good ole information here"}
    
    // Then within your site/header template you can use
    
    {embed:variable_name}
  • #3 / Jun 15, 2010 11:50am

    Focus Lab Dev Team

    1129 posts

  • #4 / Jun 15, 2010 12:38pm

    Lisa Wess

    20502 posts

    To answer the question, embeds are parsed as separate entities, that is why assigned variables are not passed down to them.  You can, as Erik said, pass the variable through the embed itself.

  • #5 / Jun 15, 2010 12:58pm

    PhilBrienesse

    187 posts

    embeded content doesn’t take variables from the parent document.  Think of it processing the information independently and then sending it back fully parsed to the parent document.  As such if you need certain information from the parent document to be available to the embeded template you pass it in a variable when you embed it.  It doesn’t have to be the weblog, it can be anything really.

    For example within an exp:weblog:entries set of tags you could use

    {exp:weblog:entries weblog="my_weblog" require_entry="yes"}
      {embed="includes/related" passed_author="{author}"}
      {other tags}
    {/exp:weblog:entries}

    Which would pass the author of the page which you could use in your embeded template which may use a completely different exp:weblog:entries call not related to the current page.

    For example

    <h2>Other Articles by {embed:passed_author}</h2>
    <p>{exp:weblog:entries weblog="a_different_weblog" dynamic="off"}<br />
      {if {embed:passed_author}=={author}}<br />
        enter code to link etc.<br />
      {/if}<br />
    {/exp:weblog:entries}

    Yes there are other ways to do that example it was just the first idea off the top of my head.
     


    Hope that helps some.

  • #6 / Jun 15, 2010 7:37pm

    Mobster

    64 posts

    I guess I imagined the ability to assign_variable globaly that would define this for the entire site as apposed to adding the variable to every embed.

    {assign_variable:entire_template="default"}

    I have heard nothing but good things about EE, not that I disagree, I just find some of the learning curves a setback and makes me wonder how many more I’m going to run into before it’s all said and done?

    thanks for all your input!

  • #7 / Jun 15, 2010 9:11pm

    PhilBrienesse

    187 posts

    If you would like a variable to be available site wide you could use the module called fresh variables it is very handy for exactly that.

    http://expressionengine.com/downloads/details/fresh_variables/

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

ExpressionEngine News!

#eecms, #events, #releases