timber context filter inside add_shortcode functionWordpress custom post, how to display custom fields on listinginsert multiple shortcodes within a shortcode wordpressFilter to remove p tag from image inside ACF WYSIWYG + TimberTimber: Exclude category methodTimber - extend data to context (WordPress)Using custom functions with TimberTimber get_posts in template/viewWordpress shortcode to get next post in taxonomy returns nothingLoop inside timber twig fileTwig_Error_Syntax for “Unknown filter” with a Twig filter in Timber

Ways of geometrical multiplication

Would a primitive species be able to learn English from reading books alone?

How do I fix the group tension caused by my character stealing and possibly killing without provocation?

Limit max CPU usage SQL SERVER with WSRM

Overlapping circles covering polygon

Can I cause damage to electrical appliances by unplugging them when they are turned on?

When and why was runway 07/25 at Kai Tak removed?

Does the Crossbow Expert feat's extra crossbow attack work with the reaction attack from a Hunter ranger's Giant Killer feature?

Proving an identity involving cross products and coplanar vectors

How do I Interface a PS/2 Keyboard without Modern Techniques?

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

Personal or impersonal in a technical resume

Can you identify this lizard-like creature I observed in the UK?

Why does the Persian emissary display a string of crowned skulls?

Language involving irrational number is not a CFL

How do you justify more code being written by following clean code practices?

ContourPlot — How do I color by contour curvature?

Air travel with refrigerated insulin

Review your own paper in Mathematics

How many people need to be born every 8 years to sustain population?

Do I have to take mana from my deck or hand when tapping a dual land?

Echo with obfuscation

Grepping string, but include all non-blank lines following each grep match

Identifying "long and narrow" polygons in with PostGIS



timber context filter inside add_shortcode function


Wordpress custom post, how to display custom fields on listinginsert multiple shortcodes within a shortcode wordpressFilter to remove p tag from image inside ACF WYSIWYG + TimberTimber: Exclude category methodTimber - extend data to context (WordPress)Using custom functions with TimberTimber get_posts in template/viewWordpress shortcode to get next post in taxonomy returns nothingLoop inside timber twig fileTwig_Error_Syntax for “Unknown filter” with a Twig filter in Timber













0















I've been trying to access timber context in add shortcode function but it doesn't seem to work.



My code is
add_action( 'init', array($this, 'create_shortcodes' ) );



public function create_shortcodes() 
add_shortcode( 'social_media', array($this, 'social_shortcode') );


public function social_shortcode($atts)
$params = shortcode_atts(array(
'id' => 0
), $atts);


$data = Helpers::create_social_media( $atts['id'], false, true );

add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );

return TimberTimber::compile('social-media.twig', array('data' => $data['content'] ));


public function add_to_context_social_media($context)
echo '<pre style="margin:200px">';
print_r($context);
echo '</pre>';

return $context;



If I add the filter inside the create_shortcodes function it works, but it doesn't isnide the add_shortcode function which also is inside the create_shortcodes function.



Any help will be appreciated.
Thanks










share|improve this question




























    0















    I've been trying to access timber context in add shortcode function but it doesn't seem to work.



    My code is
    add_action( 'init', array($this, 'create_shortcodes' ) );



    public function create_shortcodes() 
    add_shortcode( 'social_media', array($this, 'social_shortcode') );


    public function social_shortcode($atts)
    $params = shortcode_atts(array(
    'id' => 0
    ), $atts);


    $data = Helpers::create_social_media( $atts['id'], false, true );

    add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );

    return TimberTimber::compile('social-media.twig', array('data' => $data['content'] ));


    public function add_to_context_social_media($context)
    echo '<pre style="margin:200px">';
    print_r($context);
    echo '</pre>';

    return $context;



    If I add the filter inside the create_shortcodes function it works, but it doesn't isnide the add_shortcode function which also is inside the create_shortcodes function.



    Any help will be appreciated.
    Thanks










    share|improve this question


























      0












      0








      0








      I've been trying to access timber context in add shortcode function but it doesn't seem to work.



      My code is
      add_action( 'init', array($this, 'create_shortcodes' ) );



      public function create_shortcodes() 
      add_shortcode( 'social_media', array($this, 'social_shortcode') );


      public function social_shortcode($atts)
      $params = shortcode_atts(array(
      'id' => 0
      ), $atts);


      $data = Helpers::create_social_media( $atts['id'], false, true );

      add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );

      return TimberTimber::compile('social-media.twig', array('data' => $data['content'] ));


      public function add_to_context_social_media($context)
      echo '<pre style="margin:200px">';
      print_r($context);
      echo '</pre>';

      return $context;



      If I add the filter inside the create_shortcodes function it works, but it doesn't isnide the add_shortcode function which also is inside the create_shortcodes function.



      Any help will be appreciated.
      Thanks










      share|improve this question
















      I've been trying to access timber context in add shortcode function but it doesn't seem to work.



      My code is
      add_action( 'init', array($this, 'create_shortcodes' ) );



      public function create_shortcodes() 
      add_shortcode( 'social_media', array($this, 'social_shortcode') );


      public function social_shortcode($atts)
      $params = shortcode_atts(array(
      'id' => 0
      ), $atts);


      $data = Helpers::create_social_media( $atts['id'], false, true );

      add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );

      return TimberTimber::compile('social-media.twig', array('data' => $data['content'] ));


      public function add_to_context_social_media($context)
      echo '<pre style="margin:200px">';
      print_r($context);
      echo '</pre>';

      return $context;



      If I add the filter inside the create_shortcodes function it works, but it doesn't isnide the add_shortcode function which also is inside the create_shortcodes function.



      Any help will be appreciated.
      Thanks







      wordpress timber






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 6 '18 at 13:40







      Raf

















      asked Feb 6 '18 at 11:20









      RafRaf

      15219




      15219






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Would it be better to render the returned output instead of rendering it inside the shortcode ?



          $returned_shortcode = do_shortcode('[your_shortcode]');

          return TimberTimber::compile('social-media.twig', array('data' => $returned_shortcode ));





          share|improve this answer






























            0














            When you use this line



            add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );


            Then you would need to call Timber::get_context() for the filter to be applied. However, calls to Timber::get_context() are cached. This means that if you wanted to use the timber_context filter, you’d have to do add it before your first call to Timber::get_context(). If you wanted to use that in a shortcode, you probably already call Timber::get_context() in the singular or archive PHP template that displays the post’s content.



            I guess you could build up the data context for your social-media.twig template like follows:



            public function social_shortcode($atts) 
            $params = shortcode_atts(array(
            'id' => 0
            ), $atts);

            // Get cached context.
            $context = Timber::get_context();

            // Add to context.
            $context['data'] = Helpers::create_social_media(
            $atts['id'],
            false,
            true
            );

            return TimberTimber::compile( 'social-media.twig', $context );



            In addition to your custom data, you would also have the global context available in your Twig file.






            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              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',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48641831%2ftimber-context-filter-inside-add-shortcode-function%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Would it be better to render the returned output instead of rendering it inside the shortcode ?



              $returned_shortcode = do_shortcode('[your_shortcode]');

              return TimberTimber::compile('social-media.twig', array('data' => $returned_shortcode ));





              share|improve this answer



























                0














                Would it be better to render the returned output instead of rendering it inside the shortcode ?



                $returned_shortcode = do_shortcode('[your_shortcode]');

                return TimberTimber::compile('social-media.twig', array('data' => $returned_shortcode ));





                share|improve this answer

























                  0












                  0








                  0







                  Would it be better to render the returned output instead of rendering it inside the shortcode ?



                  $returned_shortcode = do_shortcode('[your_shortcode]');

                  return TimberTimber::compile('social-media.twig', array('data' => $returned_shortcode ));





                  share|improve this answer













                  Would it be better to render the returned output instead of rendering it inside the shortcode ?



                  $returned_shortcode = do_shortcode('[your_shortcode]');

                  return TimberTimber::compile('social-media.twig', array('data' => $returned_shortcode ));






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 6 '18 at 20:53









                  BeeeBeee

                  1235




                  1235























                      0














                      When you use this line



                      add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );


                      Then you would need to call Timber::get_context() for the filter to be applied. However, calls to Timber::get_context() are cached. This means that if you wanted to use the timber_context filter, you’d have to do add it before your first call to Timber::get_context(). If you wanted to use that in a shortcode, you probably already call Timber::get_context() in the singular or archive PHP template that displays the post’s content.



                      I guess you could build up the data context for your social-media.twig template like follows:



                      public function social_shortcode($atts) 
                      $params = shortcode_atts(array(
                      'id' => 0
                      ), $atts);

                      // Get cached context.
                      $context = Timber::get_context();

                      // Add to context.
                      $context['data'] = Helpers::create_social_media(
                      $atts['id'],
                      false,
                      true
                      );

                      return TimberTimber::compile( 'social-media.twig', $context );



                      In addition to your custom data, you would also have the global context available in your Twig file.






                      share|improve this answer



























                        0














                        When you use this line



                        add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );


                        Then you would need to call Timber::get_context() for the filter to be applied. However, calls to Timber::get_context() are cached. This means that if you wanted to use the timber_context filter, you’d have to do add it before your first call to Timber::get_context(). If you wanted to use that in a shortcode, you probably already call Timber::get_context() in the singular or archive PHP template that displays the post’s content.



                        I guess you could build up the data context for your social-media.twig template like follows:



                        public function social_shortcode($atts) 
                        $params = shortcode_atts(array(
                        'id' => 0
                        ), $atts);

                        // Get cached context.
                        $context = Timber::get_context();

                        // Add to context.
                        $context['data'] = Helpers::create_social_media(
                        $atts['id'],
                        false,
                        true
                        );

                        return TimberTimber::compile( 'social-media.twig', $context );



                        In addition to your custom data, you would also have the global context available in your Twig file.






                        share|improve this answer

























                          0












                          0








                          0







                          When you use this line



                          add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );


                          Then you would need to call Timber::get_context() for the filter to be applied. However, calls to Timber::get_context() are cached. This means that if you wanted to use the timber_context filter, you’d have to do add it before your first call to Timber::get_context(). If you wanted to use that in a shortcode, you probably already call Timber::get_context() in the singular or archive PHP template that displays the post’s content.



                          I guess you could build up the data context for your social-media.twig template like follows:



                          public function social_shortcode($atts) 
                          $params = shortcode_atts(array(
                          'id' => 0
                          ), $atts);

                          // Get cached context.
                          $context = Timber::get_context();

                          // Add to context.
                          $context['data'] = Helpers::create_social_media(
                          $atts['id'],
                          false,
                          true
                          );

                          return TimberTimber::compile( 'social-media.twig', $context );



                          In addition to your custom data, you would also have the global context available in your Twig file.






                          share|improve this answer













                          When you use this line



                          add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );


                          Then you would need to call Timber::get_context() for the filter to be applied. However, calls to Timber::get_context() are cached. This means that if you wanted to use the timber_context filter, you’d have to do add it before your first call to Timber::get_context(). If you wanted to use that in a shortcode, you probably already call Timber::get_context() in the singular or archive PHP template that displays the post’s content.



                          I guess you could build up the data context for your social-media.twig template like follows:



                          public function social_shortcode($atts) 
                          $params = shortcode_atts(array(
                          'id' => 0
                          ), $atts);

                          // Get cached context.
                          $context = Timber::get_context();

                          // Add to context.
                          $context['data'] = Helpers::create_social_media(
                          $atts['id'],
                          false,
                          true
                          );

                          return TimberTimber::compile( 'social-media.twig', $context );



                          In addition to your custom data, you would also have the global context available in your Twig file.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 7 at 21:54









                          GchtrGchtr

                          1,47411220




                          1,47411220



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48641831%2ftimber-context-filter-inside-add-shortcode-function%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                              2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                              Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme