Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Inelegant Blade syntax
Is there no more elegant way to do a conditional class in Blade?
<ul class="nolist">
@foreach ($docs_versions as $doc_key => $doc_version)
@if (DOCS_VERSION == $doc_key)
><a href="{{ url('docs/' . $doc_version['url_key']) }}" title="{{ $doc_version['title'] }}">{{ $doc_version['title'] }}</a></li>

This comment has been minimized.

Copy link
Owner Author

@mattstauffer mattstauffer commented Jul 30, 2014

@ericbarnes suggested ternary. I like it!

            <ul class="nolist">
                @foreach ($docs_versions as $doc_key => $doc_version)
                    <li class="{{{ DOCS_VERSION == $doc_key ? 'current' : '' }}}">
                        <a href="{{ url('docs/' . $doc_version['url_key']) }}" title="{{ $doc_version['title'] }}">{{ $doc_version['title'] }}</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment