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.
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
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
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 **/
}
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
If you use a function in your helpers file you can call the function like this :
@extends...
.. your template ..
{{ link_nested(...) }}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community