Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 587 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timber (Twig) how to call wordpress functions

#1
In Timber is this function

{{post}}
where you get things like

{{post.post_title}}
but there are other functions in WordPress like

get_the_permalink();
which are not accessible from post.get_the_permalink or post.get_permalink

these are the variables i can access

- ID
- post_author
- post_date
- post_date_gmt
- post_content
- post_title
- post_excerpt
- post_status
- comment_status
- ping_status
- post_password
- post_name
- to_ping
- pinged
- post_modified
- post_modified_gmt
- post_content_filtered
- post_parent
- guid
- menu_order
- post_type
- post_mime_type
- comment_count
- filter

As this Timber documentation describes there are actions [\[Timber Doc\]][1] but you would have to define each function in the functions.php file ... which means i would have to create each already existing function from php and "redirect" it to the wordpress function. Then bind it to Twig.

Also there was a way as you can see [here][2] which is now [deprecated][3]


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

Reply

#2
First of all, I believe you should use `{{post.link}}` to get the Permalink.

Second, if you find you often need to call php functions from your twig templates, you might not separate between code and template enough.
However, since they allow you to call Wordpress-Actions from the template, you could always write a single action in your functions.php that will, depending on the parameters, call the php-function you want. That would be very similar to the `fn()` call that was suggested.
Reply

#3
You can call any function by using for example

{{ function('get_permalink', post.ID) }}
more infos:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through