Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:53:26+00:00 2026-06-10T06:53:26+00:00

I need to render data with unknown type with filters that specific on each

  • 0

I need to render data with unknown type with filters that specific on each data type:

the rendered structures looks like:

array(
    "value"  => "value-to-render",
    "filter" => "filter-to-apply",
)

{% for item in items %}
    {{ item.value|item.filter|raw}}
{% endfor %}

So My Question is: How can I get twig to use item.filter as a filter on the value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:53:28+00:00Added an answer on June 10, 2026 at 6:53 am

    You have to write your filter, which will call filters by passing name to it.

    How to initially write you Extension you can read here.

    Assuming that you have created you extension, you have define your custom function, (e.g., customFilter).

    //YourTwigFilterExtension.php
    
    public function getFunctions()
    {
        return array(
            ...
            'custom_filter' => new \Twig_Function_Method($this, 'customFilter'),
        );
    }
    

    Then, you have to define this function

    public function customFilter($context, $filterName)
    {
        // handle parameters here, by calling the 
        // appropriate filter and pass $context there
    }
    

    After this manipulations you’ll be able to call in Twig:

    {% for item in items %}
        {{ custom_filter(item.value, item.filter)|raw  }}
    {% endfor %}
    

    Or, if you’ve defined your filter as filter (not as function):

    {% for item in items %}
        {{ item.value|custom_filter(item.filter)|raw  }}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's just say that I need to render a certain amount of HTML over
I'm writing a retro type game for the iPhone, and need to render a
I've looked around and it seems like people say you can re-render the data
I want to have display-only fields to render data that's never going to be
I need to render JSON data in my JSPs for some AJAX requests. I'd
I need to render a unordered list with the data obtained from database using
I need to render the following form: One Radio must be followed by Data
I have a webpart which uses SPGridView to render tabulated data. I need to
I need to render a URL for a JavaScript search that I am doing.
I need to render a partial view to a string within a controller action.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.