#1 April 6, 2012 11:00am

Farnsworth
Member
Registered: March 30, 2012
Posts: 13

Using Links in Templates

When building templates, it's a good idea to let BigTree generate your links. Because administrators have the ability to modify page URLs, avoiding hard-coded links keeps your site working properly.

To always link to a specific page, use $cms->getLink(), passing in the id if the page you're linking to. $cms->getLink() provides the full page URL, including http:// and a trailing slash. Read more about getLink().

$www_root always links to your homepage, including http:// and a trailing slash. Use $www_root when linking to static assets like stylesheets, javascript files, and uploads.

Finally, the "link" value returned by $cms->getNavByParent() contains a full URL for the related page. Read more about getNavByParent().

Offline

#2 April 6, 2012 12:36pm

benplum
Administrator
Registered: March 30, 2012
Posts: 54

Re: Using Links in Templates

Utilizing $www_root and $cms->getLink(), as opposed to hard coding links, also makes launching a site super simple. When moving from your development environment to your live server, simply update 3 lines in the config.php file to the new location of the site and BigTree will take care of updating all internal site links automatically:


// Simply Change:
$config["domain"] = "http://dev.example.com";
$config["www_root"] = "http://dev.example.com/";
$config["admin_root"] = "http://dev.example.com/admin/";

// To:
$config["domain"] = "http://www.example.com";
$config["www_root"] = "http://www.example.com/";
$config["admin_root"] = "http://www.example.com/admin/";

Offline

#3 July 24, 2012 12:03pm

benplum
Administrator
Registered: March 30, 2012
Posts: 54

Re: Using Links in Templates

Remember that the $config variable has be deprecated. Please use $bigtree["config"] instead.

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.