Vapor Swift - Compare two strings

260 Views Asked by At

I would like to compare a variable with a string in my leaf template.

I get the variable through the controller in my template:

<!-- NAVBAR -->
<!-- #(path) = /database -->
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <ul class="nav navbar-nav">
            #if(path == "/database") {
                <h1>Hello, there!</h1>
            }
            <li><a href="#">Filldatabase</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li><a href="#">Contact</a></li>
        </ul>
    </div>
</nav>
<!-- END NAVBAR -->

I want it so that when I am on the /database page, I get an h1 that says "Hello, there!". How can I do it? I think I need to use #if(), but I can't find the proper syntax.

1

There are 1 best solutions below

0
On BEST ANSWER

What you are looking for is the #equal() tag. You pass in two parameters, and if they are the same, if includes the HTML in the braces:

#equal("hello", "hello") {
    <!-- This is shown -->
    <p>Equal</p>
}
#equal("hello", "world") {
     <!-- This is not shown -->
     <p>Not Equal</p>
}

So what you wan to use is this:

#equal(path, "/database") {
    <h1>Hello, there!</h1>
}