helsingborg-stad / Municipio

A theme specifically made for municipalities.
MIT License
36 stars 13 forks source link

Alter HTML in Class methods #4

Open perifer opened 8 years ago

perifer commented 8 years ago

Municipio\Helper\Navigation::sidebarMenuAuto() contains HTML that we would like to alter:

        return '<nav id="sidebar-menu">
            <ul class="nav-aside hidden-xs hidden-sm">
                ' . $menu->render(false) . '
            </ul>
        </nav>';

It would be nice if that would be easier to do. Currently the only way to do it seems to be to replace sidebarMenuAuto() with our own function but it contains a lot of other logic which is a shame to duplicate.

sebastianthulin commented 8 years ago

In what way do you want to change the markup? We could add a filter, but might prefer to improve the markup itself too.

perifer commented 8 years ago

In this specific case this is our ideal markup (we are adding a header before the menu, note aria-labelledby="sidebar-menu-headline" which is added to nav):

<h2 id="sidebar-menu-headline" class="sidebar-menu__headline"><span class="visually-hidden">Undernavigation för </span>{{ $ancestor }}</h2>
<nav id="sidebar-menu" aria-labelledby="sidebar-menu-headline">
    <ul class="nav-aside hidden-xs hidden-sm">
        {{ $menu }}
    </ul>
</nav>

The most logical place to change this would to me would be in sidebar-left.blade.php or a new blade partial. I feel that there is more places like this through out Municipio that could benefit from having HTML-code in partials instead of in PHP functions.

perifer commented 8 years ago

A new example is in Municipio\Theme\Navigation::addSearchMagnifier() where we would like to remove pricon and alter classes.

sebastianthulin commented 8 years ago

Please feel free to provide us with solution examples trough a PR. Ideally we should use blade engine in most cases.

perifer commented 8 years ago

Cool. I actually looked through some of your source code to see if I could find any examples of Class methods using blade to render HTML, but didn't find anything. I'll see if I can look at this some more.

sebastianthulin commented 8 years ago

You may do something like this function to fetch a template: https://github.com/helsingborg-stad/Municipio/blob/master/library/Template.php#L98