php


How do I write the wordpress function “is_front_page()” in twig Timber code?


My goal is to simply output something only on the index page of my wordpress using Twig code. I have set a static page called Home.
I have tried this in my base.twig:
{% if is_front_page %}
Homepage content
{% endif %}
But this doesn't do anything and I just find can't easily find it for some reason.
Any help is appreciated! Thanks in advance
Timber comes with the fn (also has alias of function) that let's you execute external PHP functions. So something like this would work:
{% if fn('is_front_page') %}
Homepage content
{% endif %}
I like to keep special functions outside of my twig templates. In Timber you can define your own context where you can set your own variables.
Create a file called front-page.php and add:
<?php
$context = Timber::get_context();
// Set a home page variable
$context['is_front_page'] = 'true';
Timber::render(array('home.twig'), $context);
then you can use is_front_page as a variable just like you wanted:
{% if is_front_page %}
Homepage content
{% endif %}

Related Links

Laravel 5 database relationship accessing a data on another table
Issue with multiple image write
Phalcon get parameters are not working with lighttpd
PHP login form issue on server
how to join two different tables in mysql,with no fields common? [closed]
Php background process using proc_open
hidden value not submit in form
Show only some value from column in database with PHP code
How to select all rows from column has different value “Select All or both”
PHP error code in inserting a row in MySQL connected database [duplicate]
PHP: Design pattern for classes offering static and non-static methods
How Call the method of the controller from jquery ajax?, from laravel. Get request 404 not found url
Is $this->__invoke(); 100% safe and valid in PHP?
How to know that a new record is retrieved into a JSONArray?
how to remove whole img element with a SRC value in an UTF-8 string?
PHP get current class name in inherited class

Categories

HOME
artificial-intelligence
class
d3.js
writefile
filesize
google-play-services
jersey-2.0
mathematical-optimization
gentelella
angular-meteor
pyresttest
gtk
spring-security-oauth2
multi-step
ex
dhcp
user-defined-types
rpmbuild
jest
libgit2
altium-designer
fusetools
region
dotcms
progid
fotorama
xmlunit
custom-keyboard
amazon-kms
love2d
djcelery
netapp
icepdf
opal-framework
asihttprequest
vesta
doctrine-extensions
ipp-protocol
spongycastle
intellij-lombok-plugin
nonlinear-functions
lightning-workbench
android-webservice
gtk#
mongodb-aggregation
ptvs
sesame
java-2d
mathjs
qtcpsocket
oci
deferred-rendering
android-syncadapter
highlighting
vaadin4spring
ioexception
android-mapview
mixins
libz
com0com
abstract-factory
mgwt
debug-symbols
google-hangouts
fasterxml
comctl32
n-tier-architecture
rebar
dc
tabris
neo4jphp
tabletools
usb-flash-drive
lync-2010
insertonsubmit
stty
node.js-stream
ldif
background-thread
xalan
cgrectmake
kaazing
image-scanner
pcspim
platform-independent
uipangesturerecognizer
flymake
uploading
type-safety
yuidoc
memory-pool
kext
css-friendly
eaccelerator
mygeneration
ccnet-config
iphone-sdk-4.3
eai
accumulator

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile