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.

Passing {assign_variable} values to weblog search parameter?

November 30, 2010 3:52pm

Subscribe [3]
  • #1 / Nov 30, 2010 3:52pm

    Hi guys,

    I’m not sure if this can actually be done but I am trying to pass a variable created using the {assign_variable} function to the weblog search parameter. The variable is created by taking a segment from the url and using the uri_prettify plugin. I’m not very good at explaining things like this so here is my code below.

    {if segment_3}
    
    {assign_variable:brand="{exp:uri_prettify}{segment_3}{/exp:uri_prettify}"}
    
    <h1>{brand}</h1>
    
    {exp:weblog:entries weblog="products" search:product_brand="={brand}"}

    So ... When I place the variable between the <h1> tags it prints out correctly on the page so it is holding a value. However, it will not pull what it should from the database with the weblog search parameter.

    Maybe I’m going about this the wrong way and it can’t be done, but any help would be much appreciated 😊

    Steve.

  • #2 / Nov 30, 2010 4:21pm

    Rob Allen

    3114 posts

    Is the outputted value of {brand} exactly the same as what you have in your product_brand field? It needs to be an *exact* match letter for letter.

  • #3 / Nov 30, 2010 4:40pm

    Hi bluedreamer,

    Thanks for the response. Yep it is exactly the same word for word, capital letter for capital letter.

    I have tried to do this a couple of ways using php to store the variable and the same happens - the variable prints out correctly between the <h1> tags but wont pull the content from the weblog. However, if I hard code the value into the search parameter it displays as it should.

    Steve.

  • #4 / Nov 30, 2010 4:58pm

    Rob Allen

    3114 posts

    Ok try one thing

    Add the {brand} variable inside your weblog:entries tag to make sure it’s getting outputted.

    Also try modifying the weblog search parameter to something less specific…

    search:product_brand="{brand}"
  • #5 / Nov 30, 2010 6:28pm

    Ok I have included the {brand} variable within my weblog:entries loop and removed the search parameter.

    It is now showing all the results from the weblog (as it should) but where the output of {brand} should be a set of <a> tags are created displaying an image from somewhere else in the weblog, it displays the same image for each entry in the weblog.

    It is like the weblog:entries tag is changing the value of the variable somehow as when I put the {brand} variable after the weblog:entries loop it displays as it should.

    Probably will be something simple but really confusing me :(

  • #6 / Dec 01, 2010 9:15am

    Sue Crocker

    26054 posts

    What field type is product_brand?

  • #7 / Dec 01, 2010 10:43am

    Hi Sue, The product_brand field type is Text Input.

  • #8 / Dec 02, 2010 2:58am

    John Henry Donovan

    12339 posts

    stevenmarshdigitaldesign,

    What version and build of EE are you using?

    If you want to use the assigned variable with the search parameter you could use something like Solspace’s Preparse addon

    For the issue you arrived at what does you code look like?
    What is brand?
    Is it an image?

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

ExpressionEngine News!

#eecms, #events, #releases