Jump to content

Dynamic language string name in templates


motomac

Recommended Posts

2 hours ago, motomac said:

I need to get short weekday names dynamically. But this code in templates doesn't work:


{{$day1 = 'day_' . date( 'w', $timestamp ) . '_short';}}

{lang="$day1"}

Is it possible to do this?

Edit: scratch what I said before. What you want is

{lang="{$day1}"}

 

Link to comment
Share on other sites

On 4/10/2016 at 10:21 AM, motomac said:

I need to get short weekday names dynamically. But this code in templates doesn't work:


{{$day1 = 'day_' . date( 'w', $timestamp ) . '_short';}}

{lang="$day1"}

Is it possible to do this?

 

So you have a variable $timestamp which, presumably, holds a timestamp right? And you want to show the short form of the day (i.e. "Sun" for Sunday)?

Something like this should work

{expression="\IPS\DateTime::ts( $timestamp )->strFormat( '%a' )"}

 

This doesn't rely on language strings but rather uses the native PHP DateTime object (which is locale aware).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...