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

                              Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                              Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                              How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page