This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
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
You can probably pass it when including the component in your page markup l, like:
{% component YourComponent productid={{ productid}} %}
Tried:
{% component 'ProductPrice1' productid={{productid}} %}
No luck :(
Same result. productid is empty.
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() %}
1-5 of 5