We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Dynamic variables as tag parameters

Development and Programming

soapcreative's avatar
soapcreative
9 posts
15 years ago
soapcreative's avatar soapcreative

I have made a module to publish popular recipes on the page. I’m using it like this:

<h2>More recipes like this</h2>
            {exp:br_recipe:homepage_popular_recipes limit="3"}
                <div class="popular-recipe">
                    <div class="popular-recipe-image">
                        <div class="popular-recipe-increment-{popular_recipe_increment}"></div>
                        {popular_recipe_image_url}
                    </div>
                    <div class="popular-recipe-description">
                        <h3><a href="http://{popular_recipe_url}">{popular_recipe_title}</a></h3>
                        {popular_recipe_description}
                        <div class="popular-recipe-view-link">
                            <a href="http://{popular_recipe_url}">View</a>
                        </div>
                    </div>
                </div>
            {/exp:br_recipe:homepage_popular_recipes}

I’m using pretty much the same code on the “view recipe” page to display similar recipes, except the recipe list is generated by a different SQL query. The html is identical, just the tag name is different and the markup is different.

The urls to these pages are /general/index and /recipe/[recipe-url-title]. On the home page there is no need for a recipe id, but on the recipe page the recipe id is calculated from segment_2 to find recipes that are relevant to the recipe being viewed.

Now, I have just used pretty much the same code on two pages and I’m about to use the same code on the member profile page for “recipes by xxx”. It is becoming apparent that this should be a reusable tag, which wouldn’t be so hard only that I can’t seem to use a dynamic tag parameter. What I would like to do is this:

{exp:br_recipe:recipe_list type="member" member_name=$segment_2 limit="4"}
...
{/exp:br_recipe:recipe_list}

And if I can mange to get that working I would change the first two instances to

{exp:br_recipe:recipe_list type="popular" limit="3"}
...
{/exp:br_recipe:recipe_list}
{exp:br_recipe:recipe_list type="similar" recipe_name=$segment_1 limit="2"}
...
{/exp:br_recipe:recipe_list}

That would be a really tidy way to do it, but the problem I am having is to actually pass a dynamic variable back to the module through the tag attribute, because on /recipe/[recipe-url-title] the recipe name is segment 1, but on /contributors/profile/[username] the user name is segment 2 - the template knows this but PHP doesn’t, but more importantly it would make it more flexible if any recipe id or member id can be passed in through the template tag rather than having the module depend on those values being present in the URI, as is the case currently.

Is this possible and how can I do it?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.