This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

thomasjr53092
thomasjr53092

Hi,

I've added dynamic syntax parser variables to a layout:

{variable name="productid" label="Product Id" tab="Product" type="text"}{/variable}

This works fine, i can change the variable in static page, and show it with:

{{ productid }}

I'm trying to pass this value to my custom component:

[ProductPrice ProductPrice1]
productid="{{ productid }}"

With the following defineProperties and onRun:

public function defineProperties()
{ 
    return 
    [ 
        'productid' => 
        [
            'title'             => 'Product Id',
            'description'       => 'The id of the product to show the price of.',
            'type'              => 'string'
        ],
    ]; 
}
public function onRun()
{
    $productid = $this->property('productid');
    die($productid);
}

The page always dies empty, the content of property 'productid' is empty. I cannot pass the variable to the component. Is this by design or am i missing something?

Thanks,

Last updated

mjauvin
mjauvin

You can probably pass it when including the component in your page markup l, like:

{% component YourComponent productid={{ productid}} %}

thomasjr53092
thomasjr53092

Tried:

{% component 'ProductPrice1' productid={{productid}} %}

No luck :(

Same result. productid is empty.

bpettis
bpettis

You don't need the Twig Brackets {{ }} to pass it to the component.

{% component 'ProductPrice1' productid=productid %}

Also the better way to do this is by component function. This way it is even ran if you load the information in a partial and update the partial on an event. note my camel case

public function defineProperties()
{ 
    return 
    [ 
        'productId' => 
        [
            'title'             => 'Product Id',
            'description'       => 'The id of the product to show the price of.',
            'type'              => 'string'
        ],
    ]; 
}
public function getProductId() {
    return $this->poperty('productId');
}

Then in your Component default.htm or partial.

{% set productId = __SELF__.getProductId() %}
mjauvin
mjauvin

You're totally right about the extra {{}} bpettis, no idea why I wrote that, duh!

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.