Timber/TWIG part of {{post.content}} above, rest below












0















I need to output let's say the first 100 letters of {{post.content}} somewhere above, and then the second part of {{post.content}} below.



{{post.content.length(100)}}  //to display the first 100 characters
{{post.content.length(-100)}} //to remove the first 100 characters


The above does not seem to be working for this. I was wondering if there is a elegant solution for this (maybee built in to Timber like the ".length()" )?










share|improve this question



























    0















    I need to output let's say the first 100 letters of {{post.content}} somewhere above, and then the second part of {{post.content}} below.



    {{post.content.length(100)}}  //to display the first 100 characters
    {{post.content.length(-100)}} //to remove the first 100 characters


    The above does not seem to be working for this. I was wondering if there is a elegant solution for this (maybee built in to Timber like the ".length()" )?










    share|improve this question

























      0












      0








      0








      I need to output let's say the first 100 letters of {{post.content}} somewhere above, and then the second part of {{post.content}} below.



      {{post.content.length(100)}}  //to display the first 100 characters
      {{post.content.length(-100)}} //to remove the first 100 characters


      The above does not seem to be working for this. I was wondering if there is a elegant solution for this (maybee built in to Timber like the ".length()" )?










      share|improve this question














      I need to output let's say the first 100 letters of {{post.content}} somewhere above, and then the second part of {{post.content}} below.



      {{post.content.length(100)}}  //to display the first 100 characters
      {{post.content.length(-100)}} //to remove the first 100 characters


      The above does not seem to be working for this. I was wondering if there is a elegant solution for this (maybee built in to Timber like the ".length()" )?







      php wordpress twig timber






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 5:56









      frizzantfrizzant

      74112




      74112
























          2 Answers
          2






          active

          oldest

          votes


















          0














          If the content does not contain HTML you just could go with the slice-filter



          {{ lipsum | slice(0, 100) }}

          -----------------------------------------

          {{ lipsum | slice(100) }}


          demo






          share|improve this answer
























          • It will most likely contain html. Is there another option?

            – frizzant
            Nov 23 '18 at 14:20











          • Is it important the html stays in there for any reason? Otherwise apply striptags first

            – DarkBee
            Nov 23 '18 at 14:26













          • Yeah because i want to use it for post.content. And the user will at least be using <h1> <b> <img> etc. TAGs in there. @DarkBee

            – frizzant
            Nov 24 '18 at 6:47













          • I suggest using CSS and ellipsis then

            – DarkBee
            Nov 24 '18 at 9:50






          • 1





            If the content contains html you could break the markup. What if the content has an opening tag, e.g <div> or <p>, then you could remove the closing tag or cut an image tag in half.

            – DarkBee
            Nov 25 '18 at 1:04



















          1














          Unfortunately there's nothing built into Timber right now for this. I'd recommend writing a custom class for your post and making these discrete functions:



          <?php

          class MyPost extends TimberPost {

          function content_top() {
          //first grab what WP has in the database
          $content = $this->post_content;

          //do stuff here to get first 100 chars

          //apply WP's filters
          $content = apply_filters('the_content', ($content));
          return $content;
          }

          function content_bottom() {
          //first grab what WP has in the database
          $content = $this->post_content;

          //do stuff here to get last 100 chars

          //apply WP's filters
          $content = apply_filters('the_content', ($content));
          return $content;
          }


          Here's the guide for creating a custom post class






          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%2f53441313%2ftimber-twig-part-of-post-content-above-rest-below%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














            If the content does not contain HTML you just could go with the slice-filter



            {{ lipsum | slice(0, 100) }}

            -----------------------------------------

            {{ lipsum | slice(100) }}


            demo






            share|improve this answer
























            • It will most likely contain html. Is there another option?

              – frizzant
              Nov 23 '18 at 14:20











            • Is it important the html stays in there for any reason? Otherwise apply striptags first

              – DarkBee
              Nov 23 '18 at 14:26













            • Yeah because i want to use it for post.content. And the user will at least be using <h1> <b> <img> etc. TAGs in there. @DarkBee

              – frizzant
              Nov 24 '18 at 6:47













            • I suggest using CSS and ellipsis then

              – DarkBee
              Nov 24 '18 at 9:50






            • 1





              If the content contains html you could break the markup. What if the content has an opening tag, e.g <div> or <p>, then you could remove the closing tag or cut an image tag in half.

              – DarkBee
              Nov 25 '18 at 1:04
















            0














            If the content does not contain HTML you just could go with the slice-filter



            {{ lipsum | slice(0, 100) }}

            -----------------------------------------

            {{ lipsum | slice(100) }}


            demo






            share|improve this answer
























            • It will most likely contain html. Is there another option?

              – frizzant
              Nov 23 '18 at 14:20











            • Is it important the html stays in there for any reason? Otherwise apply striptags first

              – DarkBee
              Nov 23 '18 at 14:26













            • Yeah because i want to use it for post.content. And the user will at least be using <h1> <b> <img> etc. TAGs in there. @DarkBee

              – frizzant
              Nov 24 '18 at 6:47













            • I suggest using CSS and ellipsis then

              – DarkBee
              Nov 24 '18 at 9:50






            • 1





              If the content contains html you could break the markup. What if the content has an opening tag, e.g <div> or <p>, then you could remove the closing tag or cut an image tag in half.

              – DarkBee
              Nov 25 '18 at 1:04














            0












            0








            0







            If the content does not contain HTML you just could go with the slice-filter



            {{ lipsum | slice(0, 100) }}

            -----------------------------------------

            {{ lipsum | slice(100) }}


            demo






            share|improve this answer













            If the content does not contain HTML you just could go with the slice-filter



            {{ lipsum | slice(0, 100) }}

            -----------------------------------------

            {{ lipsum | slice(100) }}


            demo







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '18 at 8:02









            DarkBeeDarkBee

            9,44253145




            9,44253145













            • It will most likely contain html. Is there another option?

              – frizzant
              Nov 23 '18 at 14:20











            • Is it important the html stays in there for any reason? Otherwise apply striptags first

              – DarkBee
              Nov 23 '18 at 14:26













            • Yeah because i want to use it for post.content. And the user will at least be using <h1> <b> <img> etc. TAGs in there. @DarkBee

              – frizzant
              Nov 24 '18 at 6:47













            • I suggest using CSS and ellipsis then

              – DarkBee
              Nov 24 '18 at 9:50






            • 1





              If the content contains html you could break the markup. What if the content has an opening tag, e.g <div> or <p>, then you could remove the closing tag or cut an image tag in half.

              – DarkBee
              Nov 25 '18 at 1:04



















            • It will most likely contain html. Is there another option?

              – frizzant
              Nov 23 '18 at 14:20











            • Is it important the html stays in there for any reason? Otherwise apply striptags first

              – DarkBee
              Nov 23 '18 at 14:26













            • Yeah because i want to use it for post.content. And the user will at least be using <h1> <b> <img> etc. TAGs in there. @DarkBee

              – frizzant
              Nov 24 '18 at 6:47













            • I suggest using CSS and ellipsis then

              – DarkBee
              Nov 24 '18 at 9:50






            • 1





              If the content contains html you could break the markup. What if the content has an opening tag, e.g <div> or <p>, then you could remove the closing tag or cut an image tag in half.

              – DarkBee
              Nov 25 '18 at 1:04

















            It will most likely contain html. Is there another option?

            – frizzant
            Nov 23 '18 at 14:20





            It will most likely contain html. Is there another option?

            – frizzant
            Nov 23 '18 at 14:20













            Is it important the html stays in there for any reason? Otherwise apply striptags first

            – DarkBee
            Nov 23 '18 at 14:26







            Is it important the html stays in there for any reason? Otherwise apply striptags first

            – DarkBee
            Nov 23 '18 at 14:26















            Yeah because i want to use it for post.content. And the user will at least be using <h1> <b> <img> etc. TAGs in there. @DarkBee

            – frizzant
            Nov 24 '18 at 6:47







            Yeah because i want to use it for post.content. And the user will at least be using <h1> <b> <img> etc. TAGs in there. @DarkBee

            – frizzant
            Nov 24 '18 at 6:47















            I suggest using CSS and ellipsis then

            – DarkBee
            Nov 24 '18 at 9:50





            I suggest using CSS and ellipsis then

            – DarkBee
            Nov 24 '18 at 9:50




            1




            1





            If the content contains html you could break the markup. What if the content has an opening tag, e.g <div> or <p>, then you could remove the closing tag or cut an image tag in half.

            – DarkBee
            Nov 25 '18 at 1:04





            If the content contains html you could break the markup. What if the content has an opening tag, e.g <div> or <p>, then you could remove the closing tag or cut an image tag in half.

            – DarkBee
            Nov 25 '18 at 1:04













            1














            Unfortunately there's nothing built into Timber right now for this. I'd recommend writing a custom class for your post and making these discrete functions:



            <?php

            class MyPost extends TimberPost {

            function content_top() {
            //first grab what WP has in the database
            $content = $this->post_content;

            //do stuff here to get first 100 chars

            //apply WP's filters
            $content = apply_filters('the_content', ($content));
            return $content;
            }

            function content_bottom() {
            //first grab what WP has in the database
            $content = $this->post_content;

            //do stuff here to get last 100 chars

            //apply WP's filters
            $content = apply_filters('the_content', ($content));
            return $content;
            }


            Here's the guide for creating a custom post class






            share|improve this answer




























              1














              Unfortunately there's nothing built into Timber right now for this. I'd recommend writing a custom class for your post and making these discrete functions:



              <?php

              class MyPost extends TimberPost {

              function content_top() {
              //first grab what WP has in the database
              $content = $this->post_content;

              //do stuff here to get first 100 chars

              //apply WP's filters
              $content = apply_filters('the_content', ($content));
              return $content;
              }

              function content_bottom() {
              //first grab what WP has in the database
              $content = $this->post_content;

              //do stuff here to get last 100 chars

              //apply WP's filters
              $content = apply_filters('the_content', ($content));
              return $content;
              }


              Here's the guide for creating a custom post class






              share|improve this answer


























                1












                1








                1







                Unfortunately there's nothing built into Timber right now for this. I'd recommend writing a custom class for your post and making these discrete functions:



                <?php

                class MyPost extends TimberPost {

                function content_top() {
                //first grab what WP has in the database
                $content = $this->post_content;

                //do stuff here to get first 100 chars

                //apply WP's filters
                $content = apply_filters('the_content', ($content));
                return $content;
                }

                function content_bottom() {
                //first grab what WP has in the database
                $content = $this->post_content;

                //do stuff here to get last 100 chars

                //apply WP's filters
                $content = apply_filters('the_content', ($content));
                return $content;
                }


                Here's the guide for creating a custom post class






                share|improve this answer













                Unfortunately there's nothing built into Timber right now for this. I'd recommend writing a custom class for your post and making these discrete functions:



                <?php

                class MyPost extends TimberPost {

                function content_top() {
                //first grab what WP has in the database
                $content = $this->post_content;

                //do stuff here to get first 100 chars

                //apply WP's filters
                $content = apply_filters('the_content', ($content));
                return $content;
                }

                function content_bottom() {
                //first grab what WP has in the database
                $content = $this->post_content;

                //do stuff here to get last 100 chars

                //apply WP's filters
                $content = apply_filters('the_content', ($content));
                return $content;
                }


                Here's the guide for creating a custom post class







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 25 '18 at 23:54









                JaredJared

                1,290911




                1,290911






























                    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%2f53441313%2ftimber-twig-part-of-post-content-above-rest-below%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

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    Origin of the phrase “under your belt”?