Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Is it possible to "manually" build a URL


Go to End


2 Posts   2277 Views

Avatar
cevic

Community Member, 5 Posts

17 March 2008 at 1:52am

Edited: 17/03/2008 7:53am

I need to build a specifi site menu that doesn't allow me to use a loop:

<div id="tres">
	<ul>
	<li id="nav-home"><a href="#">Home</a></li>
	<li id="nav-horario"><a id=href="#">Horario</a></li>
	</ul>
</div>
<div id="cuatro">
	<ul>
	<li id="nav-ubicacion"><a href="#">Ubicacion</a></li>
	</ul>
</div>

Is there a way I can manually build urls for my menu? What I mean is, is there any page controller I can use to generate a URL (something like $Pageurl(4) will give me the same output of $Link for a specific ID)

[I just realised my question is the same as in http://www.silverstripe.com/site-builders-forum/flat/26072 which hasn't been answered yet]

Avatar
newjamie

Community Member, 7 Posts

17 March 2008 at 10:56am

Sure

You can do this with a custom controller, for example in your .php file add this to the controller:

function LinkFromID($id)
{

$thisPage = DataObject::get_by_id("Page",$id);

return $thisPage;
}

And in your template, call the controller with the ID

<% control LinkFromID(5) %>
$Link
<% end_control %>

would return the link for the page with ID 5.