Noob here. I’ve scoured the documentation for EE 2.x (unfortunately we’re stuck working in this version).
I’m NOT wanting to output the channel field values selected for a specific entry which looks simple enough–I’m wanting to just list ALL the values/IDs from a custom channel field so I can populate select box options on the frontend with ALL the options available.
Probably simple, but I can’t find the template tag/syntax for how to do this. Thank you!
Hey,
If I understand your needs correctly, all you need is a basic channel entries tag, without imposing limits?
So for example…
<select>
{exp:channel:entries channel="options" dynamic="no"}
<option value="{value}">{value}</option>
{/exp:channel:entries}
</select>
…should give you what you want. You could also use sort and orderby parameters to fine tune the order in which the entries are used etc.
Is that what you meant?
I don’t think so. Let me give you context and maybe that will help you help me. 😊
I have a channel named Resources. I have set up a channel field group for that channel (Resource Fields). In Resource Fields are all sorts of data fields: address, phone, email, etc. One of those fields is a multiselect named Counties in which all the counties to choose from are listed. So when someone publishes a new Resource entry, they can select which counties they want to apply to that resource.
However, all I’m trying to do is create a fieldset in a form in a template that lists all of the counties that are set up in that channel field…NOT as they apply to any one channel entry but just ALL the options available in the channel field in the admin.
Ah, I get you…
As far as I can tell, the only way you can do that is by using a query tag, and allowing PHP in the template (Output Parse).
<select multiple>
{exp:query sql="SELECT field_list_items FROM exp_channel_fields WHERE field_name = 'countries' "}
<?php $countries = explode("\n", "{field_list_items}");
foreach ($countries as $country){
echo "<option value='".$country."'>".$country."</option>";
}?>
{/exp:query}
</select>
Obviously you will have to check your database prefix and field shortname, but something like that would work for you I think?
It’s a bit hacky, but gets the job done 😉
I’m going to tack this on here, as it’s somewhat related.
The name of my channel field is resource_counties, and {resource_counties}
outputs the list of whatever counties were selected from the multiselect channel field within the loop. Cool.
Is there a parameter to count how many items are in it? {resource_counties:count_results}
or something simlar to that? Or does this also have to be done via PHP/SQL?
I suspect you would have to resort to PHP to make the count yourself, hopefully someone will correct me if I’m wrong. Whilst the entries tag itself has a {total_results}, to the best of my knowledge there is not a counter in place for use inside a field tag pair. Might be quite handy though!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.