How can i let the layout blocks only display a certain list of block name, maybe the blockname with prefix "article" so that no other irrelavant layout blocks are shown?
There is a "group" parameter you can set for layout blocks, and then in your layout, when you specify the block field, you pass the "group" parameter and the name of the group that you want to include. Layouts can belong to more then one group if you specify an array of names (as of a couple releases ago).
as the documentation mention that "group: if specified, will filter the options list to ONLY those block layouts with that group name ('folder' must not be specified)" in http://docs.getfuelcms.com/general/forms
// add all layouts without a group first foreach($layouts as $k => $layout) { if (empty($layout->group) AND !$layout->is_hidden()) { $options[$layout->name] = $layout->label; // reduce array down unset($layouts[$k]); } }
//ksort($options);
if (!empty($group)) { foreach($layouts as $k => $layout) { if ((is_string($layout->group) AND $layout->group == $group) OR is_array($layout->group) AND in_array($group, $layout->group)) { $options[$layout->name] = $layout->label; unset($layouts[$k]); } } }
actually by specifying a group will not ONLY listed those with the same group name but also include those without a group. so i think maybe documentation need to updated a bit. However personally i feel by specifying the group name is better to ONLY list those with the group name otherwise will defeat the purpose of the usage of grouping.
for my usage, i modified this part to
if (!empty($group)) { $options=array(); foreach($layouts as $k => $layout) { if ((is_string($layout->group) AND $layout->group == $group) OR is_array($layout->group) AND in_array($group, $layout->group)) { $options[$layout->name] = $layout->label; unset($layouts[$k]); } } }
The reason those lines are there are for when no "group" filtering parameter, the options list will have all the ungrouped pages outside of an "optgroup" tag. Perhaps another solution would be to wrap "if (!empty($group)){" check around the lines you removed? // add all layouts without a group first
if (!empty($group))
{
foreach($layouts as $k => $layout)
{
if (empty($layout->group) AND !$layout->is_hidden())
{
$options[$layout->name] = $layout->label;
// reduce array down
unset($layouts[$k]);
}
}
}
Comments
as the documentation mention that "group: if specified, will filter the options list to ONLY those block layouts with that group name ('folder' must not be specified)" in http://docs.getfuelcms.com/general/forms
// add all layouts without a group first
foreach($layouts as $k => $layout)
{
if (empty($layout->group) AND !$layout->is_hidden())
{
$options[$layout->name] = $layout->label;
// reduce array down
unset($layouts[$k]);
}
}
//ksort($options);
if (!empty($group))
{
foreach($layouts as $k => $layout)
{
if ((is_string($layout->group) AND $layout->group == $group) OR is_array($layout->group) AND in_array($group, $layout->group))
{
$options[$layout->name] = $layout->label;
unset($layouts[$k]);
}
}
}
actually by specifying a group will not ONLY listed those with the same group name but also include those without a group. so i think maybe documentation need to updated a bit. However personally i feel by specifying the group name is better to ONLY list those with the group name otherwise will defeat the purpose of the usage of grouping.
for my usage, i modified this part to
if (!empty($group))
{
$options=array();
foreach($layouts as $k => $layout)
{
if ((is_string($layout->group) AND $layout->group == $group) OR is_array($layout->group) AND in_array($group, $layout->group))
{
$options[$layout->name] = $layout->label;
unset($layouts[$k]);
}
}
}
// add all layouts without a group first if (!empty($group)) { foreach($layouts as $k => $layout) { if (empty($layout->group) AND !$layout->is_hidden()) { $options[$layout->name] = $layout->label; // reduce array down unset($layouts[$k]); } } }