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

  • Home
  • SEARCH
  • 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 8812467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:36:45+00:00 2026-06-14T03:36:45+00:00

In my template I want to output the server timezone. My template has something

  • 0

In my template I want to output the server timezone.

My template has something like

{{ getservertimezone }}

Then in the services.yml config for that bundle I have

my.twig.extension:
    class: My\WebsiteBundle\Extensions\Twig\SomeTemplateHelper
    tags:
           - { name: twig.extension }

And my SomeTemplateHelper looks like

namespace My\WebsiteBundle\Extensions\Twig;

class SomeTemplateHelper extends \Twig_Extension
{

    public function getFilters() 
    {
        return array(
            'getservertimezone'  => new \Twig_Filter_Method($this, 'getServerTimeZone'),
        );
    }

    
    public function getServerTimeZone()
    {
        if (date_default_timezone_get()) {
            return date_default_timezone_get();
        } else if (ini_get('date.timezone')) {
            return ini_get('date.timezone');
        } else {
            return false;
        }
    }

    public function getName()
    {
        return 'some_helper';
    }
    
}

But I can’t call this method unless it’s used like a filter: {{ someval | getservertimezone }}; is there a way to just do a straight {{ getservertimezone() }} call?

  • 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-14T03:36:47+00:00Added an answer on June 14, 2026 at 3:36 am

    Use getFunctions() instead of getFilters()

    public function getFunctions()
    {
        return array(
            new \Twig_SimpleFunction('server_time_zone', array($this, 'getServerTimeZone')),
        );
    }
    

    Twig filters are used to filter some value.

    {{ "some value" | filter_name_here }}
    

    Btw, you can define both filters and functions in the same class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a template class that looks something like what I have
I want to do something like this: template<template<int d, class> class container, int dim
I want to do something like template <typename T> void foo(const T& t) {
I have a custom tag in Jinja2 that I want to output something only
I want to call and template and save the output to a variable. I
I have a Django template that I want to extend in multiple places. In
I want to create a template class (let's call it Foo ) that only
Simple question. I have a list in my template and want to output the
I have: $page_file_temp = $_SERVER[PHP_SELF]; which will output: /templates/somename/index.php I want to extract from
I want a template to select from two types based on some condition. E.g.

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.