How to get a parameter value from the current URL in views-view-fields.html.twig?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I need the argument value in the theme templates and using the views-views-fields--view_name--block_1.jhtml.twig
.
I'm current getting the current URL like that:
% set url = url('current')%
Which outputs:
https://example.com/questions/12225
But I need only the 12225 value from the current url. How can I get the last parameter from the current URL in Twig?
views 8 theming
add a comment |Â
up vote
2
down vote
favorite
I need the argument value in the theme templates and using the views-views-fields--view_name--block_1.jhtml.twig
.
I'm current getting the current URL like that:
% set url = url('current')%
Which outputs:
https://example.com/questions/12225
But I need only the 12225 value from the current url. How can I get the last parameter from the current URL in Twig?
views 8 theming
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I need the argument value in the theme templates and using the views-views-fields--view_name--block_1.jhtml.twig
.
I'm current getting the current URL like that:
% set url = url('current')%
Which outputs:
https://example.com/questions/12225
But I need only the 12225 value from the current url. How can I get the last parameter from the current URL in Twig?
views 8 theming
I need the argument value in the theme templates and using the views-views-fields--view_name--block_1.jhtml.twig
.
I'm current getting the current URL like that:
% set url = url('current')%
Which outputs:
https://example.com/questions/12225
But I need only the 12225 value from the current url. How can I get the last parameter from the current URL in Twig?
views 8 theming
views 8 theming
edited 30 mins ago
leymannx
5,32742255
5,32742255
asked 1 hour ago


Narinder Bajwa
141
141
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
I don't know it is best way or not but can help you
You are using the % set url = url('current>') %
After dump, it turned out that's what
array(3)
["#markup"]=>
string(23) "http://example.com/category" ["#cache"]=> array(3)
["contexts"]=> array(2) [0]=> string(5) "route" [1]=>string(8)
"url.site" ["tags"]=> array(0) ["max-age"]=> int(-1)
["#attached"]=> array(0)
Convert array to sting
% set url = url('current>')['#markup'] %
url
you will get the last value from theurl
Is this a typo'current>'
the trailing angle bracket?
– leymannx
46 mins ago
<current> showing as blank in the comment so i have to type this but its value will not changes after url change , aftrer cache flush its value change
– Manmeet Khurana
44 mins ago
add a comment |Â
up vote
1
down vote
You could use Twig's split
filter, though I don't recommend scripting too much inside templates.
Instead I recommend to pass the value over to Twig from a preprocess function from inside your theme or a custom module via template_preprocess_views_view_fields
.
/**
* Implements template_preprocess_views_view_fields().
*/
function MYTHEME/MYMODULE_preprocess_views_view_fields(&$variables)
// Retrieve an array which contains the path pieces.
$current_path = Drupal::service('path.current')->getPath();
if ($current_path[0] == 'questions')
$variables['question_id'] = $current_path[1];
And then inside your template print it for example like so:
% if question_id %
<div id=" question_id ">Question ID: question_id </div>
% endif %
You are the best , I also learned today alot from you .
– Manmeet Khurana
19 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
I don't know it is best way or not but can help you
You are using the % set url = url('current>') %
After dump, it turned out that's what
array(3)
["#markup"]=>
string(23) "http://example.com/category" ["#cache"]=> array(3)
["contexts"]=> array(2) [0]=> string(5) "route" [1]=>string(8)
"url.site" ["tags"]=> array(0) ["max-age"]=> int(-1)
["#attached"]=> array(0)
Convert array to sting
% set url = url('current>')['#markup'] %
url
you will get the last value from theurl
Is this a typo'current>'
the trailing angle bracket?
– leymannx
46 mins ago
<current> showing as blank in the comment so i have to type this but its value will not changes after url change , aftrer cache flush its value change
– Manmeet Khurana
44 mins ago
add a comment |Â
up vote
1
down vote
I don't know it is best way or not but can help you
You are using the % set url = url('current>') %
After dump, it turned out that's what
array(3)
["#markup"]=>
string(23) "http://example.com/category" ["#cache"]=> array(3)
["contexts"]=> array(2) [0]=> string(5) "route" [1]=>string(8)
"url.site" ["tags"]=> array(0) ["max-age"]=> int(-1)
["#attached"]=> array(0)
Convert array to sting
% set url = url('current>')['#markup'] %
url
you will get the last value from theurl
Is this a typo'current>'
the trailing angle bracket?
– leymannx
46 mins ago
<current> showing as blank in the comment so i have to type this but its value will not changes after url change , aftrer cache flush its value change
– Manmeet Khurana
44 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
I don't know it is best way or not but can help you
You are using the % set url = url('current>') %
After dump, it turned out that's what
array(3)
["#markup"]=>
string(23) "http://example.com/category" ["#cache"]=> array(3)
["contexts"]=> array(2) [0]=> string(5) "route" [1]=>string(8)
"url.site" ["tags"]=> array(0) ["max-age"]=> int(-1)
["#attached"]=> array(0)
Convert array to sting
% set url = url('current>')['#markup'] %
url
you will get the last value from theurl
I don't know it is best way or not but can help you
You are using the % set url = url('current>') %
After dump, it turned out that's what
array(3)
["#markup"]=>
string(23) "http://example.com/category" ["#cache"]=> array(3)
["contexts"]=> array(2) [0]=> string(5) "route" [1]=>string(8)
"url.site" ["tags"]=> array(0) ["max-age"]=> int(-1)
["#attached"]=> array(0)
Convert array to sting
% set url = url('current>')['#markup'] %
url
you will get the last value from theurl
answered 54 mins ago


Manmeet Khurana
1558
1558
Is this a typo'current>'
the trailing angle bracket?
– leymannx
46 mins ago
<current> showing as blank in the comment so i have to type this but its value will not changes after url change , aftrer cache flush its value change
– Manmeet Khurana
44 mins ago
add a comment |Â
Is this a typo'current>'
the trailing angle bracket?
– leymannx
46 mins ago
<current> showing as blank in the comment so i have to type this but its value will not changes after url change , aftrer cache flush its value change
– Manmeet Khurana
44 mins ago
Is this a typo
'current>'
the trailing angle bracket?– leymannx
46 mins ago
Is this a typo
'current>'
the trailing angle bracket?– leymannx
46 mins ago
<current> showing as blank in the comment so i have to type this but its value will not changes after url change , aftrer cache flush its value change
– Manmeet Khurana
44 mins ago
<current> showing as blank in the comment so i have to type this but its value will not changes after url change , aftrer cache flush its value change
– Manmeet Khurana
44 mins ago
add a comment |Â
up vote
1
down vote
You could use Twig's split
filter, though I don't recommend scripting too much inside templates.
Instead I recommend to pass the value over to Twig from a preprocess function from inside your theme or a custom module via template_preprocess_views_view_fields
.
/**
* Implements template_preprocess_views_view_fields().
*/
function MYTHEME/MYMODULE_preprocess_views_view_fields(&$variables)
// Retrieve an array which contains the path pieces.
$current_path = Drupal::service('path.current')->getPath();
if ($current_path[0] == 'questions')
$variables['question_id'] = $current_path[1];
And then inside your template print it for example like so:
% if question_id %
<div id=" question_id ">Question ID: question_id </div>
% endif %
You are the best , I also learned today alot from you .
– Manmeet Khurana
19 mins ago
add a comment |Â
up vote
1
down vote
You could use Twig's split
filter, though I don't recommend scripting too much inside templates.
Instead I recommend to pass the value over to Twig from a preprocess function from inside your theme or a custom module via template_preprocess_views_view_fields
.
/**
* Implements template_preprocess_views_view_fields().
*/
function MYTHEME/MYMODULE_preprocess_views_view_fields(&$variables)
// Retrieve an array which contains the path pieces.
$current_path = Drupal::service('path.current')->getPath();
if ($current_path[0] == 'questions')
$variables['question_id'] = $current_path[1];
And then inside your template print it for example like so:
% if question_id %
<div id=" question_id ">Question ID: question_id </div>
% endif %
You are the best , I also learned today alot from you .
– Manmeet Khurana
19 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You could use Twig's split
filter, though I don't recommend scripting too much inside templates.
Instead I recommend to pass the value over to Twig from a preprocess function from inside your theme or a custom module via template_preprocess_views_view_fields
.
/**
* Implements template_preprocess_views_view_fields().
*/
function MYTHEME/MYMODULE_preprocess_views_view_fields(&$variables)
// Retrieve an array which contains the path pieces.
$current_path = Drupal::service('path.current')->getPath();
if ($current_path[0] == 'questions')
$variables['question_id'] = $current_path[1];
And then inside your template print it for example like so:
% if question_id %
<div id=" question_id ">Question ID: question_id </div>
% endif %
You could use Twig's split
filter, though I don't recommend scripting too much inside templates.
Instead I recommend to pass the value over to Twig from a preprocess function from inside your theme or a custom module via template_preprocess_views_view_fields
.
/**
* Implements template_preprocess_views_view_fields().
*/
function MYTHEME/MYMODULE_preprocess_views_view_fields(&$variables)
// Retrieve an array which contains the path pieces.
$current_path = Drupal::service('path.current')->getPath();
if ($current_path[0] == 'questions')
$variables['question_id'] = $current_path[1];
And then inside your template print it for example like so:
% if question_id %
<div id=" question_id ">Question ID: question_id </div>
% endif %
edited 38 mins ago
answered 49 mins ago
leymannx
5,32742255
5,32742255
You are the best , I also learned today alot from you .
– Manmeet Khurana
19 mins ago
add a comment |Â
You are the best , I also learned today alot from you .
– Manmeet Khurana
19 mins ago
You are the best , I also learned today alot from you .
– Manmeet Khurana
19 mins ago
You are the best , I also learned today alot from you .
– Manmeet Khurana
19 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f269697%2fhow-to-get-a-parameter-value-from-the-current-url-in-views-view-fields-html-twig%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password