How to get a parameter value from the current URL in views-view-fields.html.twig?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question





























    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?










    share|improve this question

























      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 30 mins ago









      leymannx

      5,32742255




      5,32742255










      asked 1 hour ago









      Narinder Bajwa

      141




      141




















          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






          share|improve this answer




















          • 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


















          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 %





          share|improve this answer






















          • You are the best , I also learned today alot from you .
            – Manmeet Khurana
            19 mins ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "220"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          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






























          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






          share|improve this answer




















          • 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















          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






          share|improve this answer




















          • 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













          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






          share|improve this answer












          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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

















          • 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













          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 %





          share|improve this answer






















          • You are the best , I also learned today alot from you .
            – Manmeet Khurana
            19 mins ago














          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 %





          share|improve this answer






















          • You are the best , I also learned today alot from you .
            – Manmeet Khurana
            19 mins ago












          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 %





          share|improve this answer














          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 %






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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
















          • 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

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          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













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          One-line joke