b:env.root

<b:env.root />

URL of the site root

URLs and paths inside Bildy all refer to a relative point which is the root of the site, for example "/products/cheese".

Bildy site may not always be located at the root of a domain but instead in some sub directory (like www.mydomain.com/finland/). In these cases links created with the tags in Bildy wouldn't work. To keep data portability high, it's recommended to use <b:env.root/> in the beginning of your links. This means that when the site location changes or data is deployed elsewhere (for example www.mydomain.com/fi), links won't get broken.

On the other hand, if you are sure that the site will always remain at the root you should never have to use this tag.

Note: When you're querying data from Bildy with URLs, you should not use <b:env.root/> since all URLs in Bildy are relative to the Bildy site's root.

Attributes

show

(optional)
This attribute currently allows for only one value: domain. If it is set, domain of the site will be shown in addition to the root of the site. The output will be identical to <b:env.domain /> if the Bildy site is located on the domain root.

Examples

Using b:env.root

If your site is not running in domain root, you'll need to use <b:env.root/> when creating navigation. Here's an example of creating a navigation that doesn't break if the site moves.

<b:getstucture name="navigation" parent="/">
    <b:before><ul></b:before>
    <li>
        <a href="<b:env.root/><b:navigation.url/>">
            <b:navigation.name/>
        </a>
        <b:navigation.recursion parent="<b:navigation.url/>"/>
    </li>
    <b:after></ul></b:after>
</b:structure>

Using <b:env.root /> alone in links

<b:env.root/> doesn't work properly when it's used by itself if the Bildy site is at domain root. The problem is that when you're running a site under a folder, <b:env.root/> has a value (e.g. /finland) and links work just fine. However if the site is at domain root, <b:env.root/> will be empty. This means that in a link the href attribute will be empty and empty links link to the current page, not to the root as intended.

This can be avoided this by placing / -character after <b:env.root/> when using it alone.

If it is certain that the site will remain at the root of the domain not using the tag at all and using just / instead is the best solution.

In this example the site is at the root of the domain:

This doesn't work: <a href="<b:env.root/>">Back to home</a>

Fixed: <a href="<b:env.root/>/">Back to home</a>
HTML source output
This doesn't work: <a href="">Back to home</a>

Fixed: <a href="/">Back to home</a>