Support the ongoing development of Laravel.io →
posted 9 years ago
Views
Last updated 1 year ago.
0

You should checkout the doc : http://laravel.com/docs/html#custom-macros

Your code inside the macro should be raw PHP. You can also use HTML/FORM... Facades and laravel helper functions.

Last updated 1 year ago.
0

CaporalDead.

You mean something like this :

<a href="<?php echo URL::to('/'); ?>"><span>Home</span></a>

or if you mean something else can you give me a example.

Roelof

Last updated 1 year ago.
0

Oke,

I found this solution :

<?php namespace app\lib\Support\Facades;


class HTML extends \Illuminate\Support\Facades\HTML {

	public static function link_nested($url, $title = null, $attributes = array(), $secure = null, $nested = null) 
	{
		$url = URL::to($url, array(), $secure);

		$title = $title ?: $url;

		if (empty($attributes))	$attributes = null;

		return '<a href="'.$url.'"'.static::attributes($attributes).'>'.$nested.''.static::entities($title).'</a>';
	}
}

change the aliases array's HTML key with this in your app.php

'HTML'            => 'app\lib\Support\Facades\HTML',

add these to your autoload key in your composer.json

"app/lib",
			"app/lib/Support",
			"app/lib/Support/Facades"

and run composer install and update.

You've successfully extended the HTML class.

One question left : How can I use this into my template:

{{ HTML: link nested ( ) }} 

maybe ?

Roelof

Last updated 1 year ago.
0

You can just put this code into your helpers.php file :

<?php

function link_nested($url, $title = null, $attributes = array(), $secure = null, $nested = null) 
{
    /** your code here **/
}
Last updated 1 year ago.
0

yes, I know but that is not my question.

If I have that function how I can I use it in a template like layout.blade,html

Roelof

Last updated 1 year ago.
0

If you use a function in your helpers file you can call the function like this :

@extends...

.. your template ..

{{ link_nested(...) }}
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.