In My route:
Route::get('/item/{itemId?}', 'ItemController#index');
Controller returning to:
http://example.com/item/12
But in blade don't showed {{Request::segment(3);}}
Please, help! And sorry for my English
It should be segment(2):
{{ Request::segment(2) }}
And segment(1) will return "item"
Your route has 2 segments! so if you need id it's in segment2
{{ Request::segment(2) }}
segment 1 will be equal to items
{{ Request::segment(1) }} //items
Related
UPDATE
refering to Oleg Butuzov answer i can solve my first problem with :
{{ $paginator := .Paginate (where .Site.RegularPages ".Params.yt" ">" "") 1 }}
but i have new problem that its listing all post on content folder Hugo that contain param "yt", and then i solve my problem from Official Hugo Discusion here https://discourse.gohugo.io/t/complex-where-filter-using-and-or-not/5758/3 from #bep reply.
and here.. how to filtering where HUGO with two condition :
{{ $paginator := .Paginate (where (where .Site.RegularPages ".Params.yt" ">" "") ".Params.type" "post") 1 }}
i update and clearing this Question because its realy hard to find about this Hugo Question and i hope its can solve your problem too.. thx :)
======= ORIGINAL QUESTION ======
how to filter "where" for Variable $Paginator to only listing post that contain Custom param "yt"?
{{ $paginator := .Paginate (where .Site.RegularPages "Type" "post") 2 }}
{{ range $paginator.Pages }}
{{ .Params.yt }}
{{ end }}
{{ template "_internal/pagination.html" . }}
my Hugo Template structure :
conten/Post/
---- post1.md
---- post2.md
theme/layout/post/gameplay.html
then
post1.md
---
Title: Title 1
type: post
yt: ytchannelid
---
post2.md
---
Title: Tile 2
type: post
---
thanks before :)
You can use combination of .Params and comparison operators.
So, for example, I want to show the only projects with forks on the project page.
{{ define "content" }}
{{ range first 6 (where .Paginator.Pages ".Params.Forks" ">" "") }}
<div class="inner">
<pre>[{{.Params.Forks}}]</pre>
<hr>
</div>
{{ end }}
{{ end }}
see more at where manual page.
In blade, If we want to check that the current route matches with a route or not, we can simply use:
#if(Route::currentRouteName() == 'parameter')
{{ 'yes' }}
#else
{{ 'no' }}
#endif
But what if we want to match it with a wildcard like:
#if(Route::currentRouteName() == 'parameter.*')
{{ 'yes' }}
#else
{{ 'no' }}
#endif
Is there any solution for that?
I have tried "*" and ":any", but it didn't work.
Note: I want to check route, not URL.
Any help would be appreciated.
Thanks,
Parth Vora
Use Laravel's string helper function
str_is('parameter*', Route::currentRouteName())
It'll return true for any string that starts with parameter
I had the same problem. I wanted to toggle an active class based on a URI.
In blade (Laravel 6x), I did:
(request()->is('projects/*')) ? 'active' : ''
You can also make use of Blades Custom If Statements and write something like this in your AppServiceProvider.php:
public function boot()
{
Blade::if('route', function ($route) {
return Str::is($route, Route::currentRouteName());
});
}
then you can use it in a blade view like this:
<li #route('admin.users*') class="active" #endroute>
Users
</li>
I have to get the domain url (ex. http://www.example.com/) in laravel blade. I've tried using {{ url() }} but it returns the path to my public directory. Is there any one line function to get this? How do I get the domain in blade? Need help. Thanks.
You can also try
{{ Request::server ("SERVER_NAME") }}
{{ Request::server ("SERVER_NAME") }}
Or go with
{{ Request::root() }}
i try to to show data from database article...the content is contain html tags and long text..
so i want make a read more and convert tag html to html view..
this is my code is run :
{{ HTML::decode($show->content) }}
{{ str_limit($show->content, $limit=100, $end=' ...') }}
i try this :
{{ HTML::decode(str_limit($show->content,$limit=100, $end=' ...')) }}
{{ str_limit(HTML::decode($show->content),$limit=100, $end=' ...') }}
but not show ( blank )
annyone can help me to fix it??
thank u b4
Is {{ $show->content }} returning any data to format?
Is your template is .blade?
Maybe it placed somewhere in HTML, where it is not visible?
Try to use this construction with some predefined string to find out if it works. Here is working example:
{{ str_limit('Some big text', $limit = 5, $end='...') }}
{{ Form::text('username', Input::old('username')) }}
This is my code, I want to add Username as placeholder in the text box. I already use bootstrap in the project.
I tried to use the example
{{ Form::text('username', 'Username', Input::old('username')) }}
But it gives a default value which needs to be deleted and then the user has to type his value. I want something like how it shows up on Twitter.com etc. Which gets erased once user types into it.
{{ Form::text('username', Input::old('username'), array('placeholder'=>'Username')) }}
This works for Laravel 4!!
{{ Form::text('username', null, array('placeholder'=>'Username' )); }}
Use:
{{ Form::text('txtUsername', '',array('class'=>'input', 'placeholder'=>'Username')) }}
Been a while since this was updated but with Former for Laravel the way to do this would be:
Former::text('field')->placeholder('langfile.path.to.placeholder.text')))
The lang file would be called langfile.php with the array containing:
<?php
return array (
'path.to.placeholder.text' => 'Some Placeholder Text.'
);
In case somebody wonders how this should work for a password field:
{{ Form::password('password', array('placeholder'=>'Password')) }}