开发者

Print path to base in template override

开发者 https://www.devze.com 2023-02-20 06:36 出处:网络
I am doing a template override with my template.php, and I need to print the path to the base of my site.

I am doing a template override with my template.php, and I need to print the path to the base of my site.

Currently I have this:

$output = '<div id="my-basket-text"><a href="/cart">My Basket</a></div>' . '<div id="my-basket-no-items">' . $item_count . '</div>';

The link created is:

<a href="/cart">My Basket </a>

I understand why this is happening and why this link doesn't work.

If I was adding code to a tpl file, I would use PHP to print the path to the base of my site first. However using the same code in my template.php doesn't work; the code is shown as text on the page.

How can I get around this? Am I trying to do it in the right way?

NOTE - The code $item_count works fine as it is, but w开发者_如何转开发hen I tried to use it to add a class to a div it also just printed the text: '' . $item_count . ''.

This makes me wonder if I am using the correct code for the base path, but applying it wrongly.


You need to use drupal's link function l(). Check this page for the url's options available.

So, your link should be

$output = l('My Basket', 'cart');

If you use that for your links, Drupal will handle the base path for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消