Timber/TWIG part of {{post.content}} above, rest below
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
add a comment |
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
add a comment |
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
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
php wordpress twig timber
asked Nov 23 '18 at 5:56
frizzantfrizzant
74112
74112
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
If the content does not contain HTML
you just could go with the slice
-filter
{{ lipsum | slice(0, 100) }}
-----------------------------------------
{{ lipsum | slice(100) }}
demo
It will most likely contain html. Is there another option?
– frizzant
Nov 23 '18 at 14:20
Is it important thehtml
stays in there for any reason? Otherwise applystriptags
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 containshtml
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
|
show 2 more comments
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
add a comment |
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
});
}
});
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
Required, but never shown
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
If the content does not contain HTML
you just could go with the slice
-filter
{{ lipsum | slice(0, 100) }}
-----------------------------------------
{{ lipsum | slice(100) }}
demo
It will most likely contain html. Is there another option?
– frizzant
Nov 23 '18 at 14:20
Is it important thehtml
stays in there for any reason? Otherwise applystriptags
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 containshtml
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
|
show 2 more comments
If the content does not contain HTML
you just could go with the slice
-filter
{{ lipsum | slice(0, 100) }}
-----------------------------------------
{{ lipsum | slice(100) }}
demo
It will most likely contain html. Is there another option?
– frizzant
Nov 23 '18 at 14:20
Is it important thehtml
stays in there for any reason? Otherwise applystriptags
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 containshtml
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
|
show 2 more comments
If the content does not contain HTML
you just could go with the slice
-filter
{{ lipsum | slice(0, 100) }}
-----------------------------------------
{{ lipsum | slice(100) }}
demo
If the content does not contain HTML
you just could go with the slice
-filter
{{ lipsum | slice(0, 100) }}
-----------------------------------------
{{ lipsum | slice(100) }}
demo
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 thehtml
stays in there for any reason? Otherwise applystriptags
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 containshtml
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
|
show 2 more comments
It will most likely contain html. Is there another option?
– frizzant
Nov 23 '18 at 14:20
Is it important thehtml
stays in there for any reason? Otherwise applystriptags
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 containshtml
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
|
show 2 more comments
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
add a comment |
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
add a comment |
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
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
answered Nov 25 '18 at 23:54
JaredJared
1,290911
1,290911
add a comment |
add a comment |
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.
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
Required, but never shown
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
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
Required, but never shown
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
Required, but never shown
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
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