fred
fred copied to clipboard
[Question] Can I build dynamic optionset or bind TV select box selection to twig?
Hi,
So here's the situation: I am working on a project with custom database tables and I am trying to find a way to integrate this with Fred. My idea would be to use a TV to generate the results to be shown on fred optionset with type as select:
{
"name": "cta_class",
"label": "CTA Class",
"type": "select",
"options": {
"danger": "Red CTA",
"info": "Blue CTA",
"default": "Default CTA"
},
"value": "default"
}
I know this does not exist as per today, but my question is to understand if this being considered or if there is an alternative way to do this.
I am able to build a select box TV based on custom tables with Dynamicdropdown Extra and this works really well. I am even able to add it to the frontend.
I know that fred bind can be used for these ind of situations. This is what I found on the documentation:
<div data-fred-name="name" data-fred-render="false">John Doe</div>
<div class="modal">
<div class="modal-header" data-fred-bind="name"></div>
<div class="modal-content">Hello there</div>
</div>
The question is: Can I bind the select box selection value to a twig variable in order to use it to generate the content of the element dynamically? I am using a custom snippet for this, and the twig variable would be one of the arguments I would have to use to build it and get the dynamic content properly.
Many thanks in advance .
Well, I was able to go around this creating a new field on my custom DB having a field with linked resource, and the module will cross-check the current resource ID with the line having the resource ID reference, and deliver the results.
But having a way to build dynamic select boxes in the option sets would be a really great option :)
I don't understand what you are trying to do.
You can't generate option sets from snippets/tv/chunk, they are static.
You can use value from the element setting and pass it to a snippet:
[[someSnippet? &cta_class=`{{ cta_class }}`]]
Twig parses first and replaces the placeholder with the value from settings and then MODX parses the rest.
Hi John,
My Idea would be exactly the opposite. Have a way to call a snippet from the optionset to dynamically generate the options on the optionset for "select" field type. But you just said that these are static, so no go.
Additionally, from what I could read, it is not possible to assign a twig var based on a frontend selectbox selection and have it reflected on the current element, while fred is active. Twig is rendered server-side, No go here as well.
So the last point that remains is: Do you think it could be useful in the future to have a feature that would allow to call a snippet from the optionset field to dynamically generate the options?
Thanks in advance
that's the same I am looking for I guess...
I'm havin a listbox-TV which options get generated by some db-entries (from the Extra FAQ Manager):
@SELECT 'FAQ auswählen' AS username, 0 AS id UNION ALL
SELECT `name` AS `name`,`id` FROM `[[+PREFIX]]faqman_set`
I would also want this listbox as an option-set in a fred-element.
Right now I need to add each created new FAQ-set manually to the options:
"options": {
"1": "FAQ1",
"2": "FAQ2",
"4": "FAQ3",
...
},
So no chance to get this done?
Option Sets are purely static.
Hi John,
Is something related with this planned (or in the roadmap of fred) in order to bring some dynamic behavior to the option sets?
This can be really useful and take fred into other stage. Nobody else from the other CMSs has this as of now. This will open a new world of possibilities, and will not change Fred core philosophy.
I know this can be complex, as will certainly require complex changes in order to process tags in optionsets and, re-validate json after snippet/chunk parsing. If we can have this, then this will be kick-ass.
Please, consider this for the future, if possible.
Option Sets are purely static.
@theboxer And are they completely planned to stay this way?
Couldn't a second options-option, like optionsElement
or optionsGenerator
, be introduced, that delivers some options dynamically (in the needed format) from a chunk or snippet?
Something like this:
{
"name": "slider_dirs",
"label": "Slider Directory",
"type": "select",
"optionsElement": "GetSliderDirOptions",
"value": ""
}
This is also something I would love to see. Having the option to use a snippet or MODX @ bindings to generate a dynamic list would be awesome. For me I am using this to embed forms that connects to MailChimp and it would be great if the "Audience List" could be dynamic using MailchimpGetLists
snippet provided by Mail Chimp for MODX (https://sterc.com/en/modx/extras/mailchimp-for-modx)
I'll bump this. Having access to MODX placeholders in option sets would be nice. Up till now I've been using the Content Blocks extra by modmore, and after acquainting myself with FRED, I was hoping to make the switch to it. Dynamic option sets would seal the deal for me.
I'll upvote this too, I've run into several instances where it would be great to be able to manipulate the option set via tags or snippets.