This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I have created one plugin (call it Product) using Builder Plugin and inside it, i have a dropdown (call it product_category (Product Category))
Using Builder Plugin, i have added few Key => Value (Dropdown Category options) like below.
Added Dropdown Options:
Showing Dropdown Options:
Now i have one CMS page (call it products) which i am showing in front end, and in which i am showing the list of the products, which works fine using the code like below.
Now here comes my question/query, i have a Product Category Dropdown in front end as well in a same page and i want to get all the Product Categories which i have added using my Builder Plugin.
How can i get those ?
You can try using the solution presented here: http://octobercms.com/forum/post/using-backend-forms-in-frontend
Keep in mind that the from configuration is a simple YAML file (fields.yaml
), so you should also be able to parse this and extract the options.
@alxy thanks for your reply but i am still confused after reading the above thread. Can you help me by providing me a chunk of code if possible based on the screenshots i have provided above ? it would be great help and i can clarify myself more.
Thanks
Additionally, i have tried to use this one and it almost worked for me.
print_r(Product::lists('product_brand'));
but it is giving me values from database instead of my default drop-down values. Any other way ?
The easiest was I can think of is to actually parse the fields.yaml
. Here you can find the Parser class: https://github.com/octobercms/library/blob/master/src/Parse/Yaml.php
Code may look like this:
$parser = new October\Rain\Parse\Yaml;
$fields = $parser->ParseFile('/path/to/fields.yaml');
var_dump($fields);
Thanks @alxy The solution worked for me too. I leave this code for a little bit more explained
For inject the dropdown options to the template. In the component:
use October\Rain\Parse\Yaml;
$parser = new Yaml;
$path = plugins_path().'/polillastudio/kannski/additional/populate/countries.yaml';
$countries = $parser->ParseFile($path);
$this->page['countries'] = $countries;
For inject the options to a dropdown backend form. Assuming you fill the dropdown with the get---Options function
public function getCountryOptions()
{
$parser = new Yaml;
$path = plugins_path().'/polillastudio/kannski/additional/populate/countries.yaml';
$countries = $parser->ParseFile($path);
return $countries;
}
1-8 of 8