specify a group of block name

edited September 2014 in Modules
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?

Comments

  • edited 8:43AM
    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).
  • edited September 2014
    i checked fuel layouts.php class

    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]);
    }
    }
    }
  • edited 8:43AM
    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]); } } }
  • edited 8:43AM
    good solution, thanks
  • edited 8:43AM
    I've posted that as a fix in the develop branch.
Sign In or Register to comment.