How do I format time to hh:mm using Twig (Symfony) - html

I retrieve a timefield from my MS SQL database, for example '10:30:00' (hh:mm:ss). I try to render this in a twig template, but I only want to display the '10:30' portion (hh:mm).
I've tried to get this done using both number_format and date_format, but I can't seem to get it done. For example, a failed attempt would be:
<td class="PODTIME">{{ record.PODTIME|number_format(2, ':') }}</td>
Yeah that doesn't make sense. But I can't find anything even remotely close to what I want - I guess I'm overlooking something.
Thanks

You can use the Twig filter date like this :
{{ object.date|date('H:i:s') }}
As seen on this thread : How to render a DateTime object in a Twig template

Related

How do I return a value from database to template?

I have a database that uses formset to help store data. How do I get the ‘value’ of the numbers of data in the template? For example, I got a queryset of {[Item 1],[ Item 2]}. How do I get the value of 2 in the template to tell me there's 2 items? I want to use this value to control the amount of stuff I can clone with a click of the button. I'm using Django for the web
You just ask |length of the queryset, like:
{{ queryset|length }}
will be returning the number of element

Ng-repeat in Sightly

I am trying to populate drop-down values using ng-repeat in Sightly. The AEM node saves my data as String array and I am able to fetch it properly, but not able to populate them as it throws "? undefined:undefined ?" error.
My code:
<select name="${validation.elementName}" id="${validation.elementName}" ng-model="${validation.elementName}" ng-change="${properties.clickfunction}">
<option ng-repeat="opt in ${properties.options}" value={{opt}}>opt</option>
</select>
And the output:
:
Is there anything I am missing? As Sightly is totally new to me. I will be very grateful for any help to improve this code or pointing my mistake.
First of all, you need to wrap the data you pass to value in quotes, so it should be like this:
value="{{opt}}"
Second, it looks like you are passing the values without single quotes and they are not being recognized as strings. Take a look at this plunker:
http://plnkr.co/edit/A2gZJbvVV9ozHloLkF4B?p=preview
You can see that the first ng-repeat works as expected, but the second throws an error in the console and doesn't display anything. Basically, you just need to put quotes around each string in your array.
Thanks #Victor for your reply.
Please find my below findings.
value="{{opt}}" was my mistake while pasting the code to stackoverflow.
${properties.options} returns string array.
ng-repeat seems to parse correctly as per this output.

Passing properties in Semantic MediaWiki

Currently I have 3 categories, Application, Application Instance and Vendor.
Right now Application has a link (via property Made By) to Vendor. Application instances need to link back to Vendor via a property. I have the query I can use to return the application name and vendor is
{{#ask:
[[Category:Program]][[{{{Program}}}]]
|?Made By
}}
however
{{#set:Made By={{#ask:
[[Category:Program]][[{{{Program}}}]]
|?Made By
}}}}
doesn't work to set the property to the value of vendor which is returned by the ask query.
Are there other ways to do this?
Maybe a bit late but you could probably do this using a template to set the property. Something like this?
In the Application Instance template (or manually on each Application Instance page) add the following ask query:
{{#ask:[[Category:Program]][[{{{Program}}}]]
|?Made By
|link=none
|format=template
|template=Set made by
}}
Then create the template "wiki/Template:Set made by" with the following:
includeonly>
{{#set:
Made By={{{2}}}
}}
</includeonly>
Notes
Parameter {{{1}}} is the subject which is the page name and {{{2}}} will be the result for 'Made By'.
Stripping the link from the query results prevents the extra text being passed to the set command which would confuse things.
You can also use the inverse of properties in queries by adding a minus sign in front of them. (e.g. '-Made By')

Can I allow paging in the contenttype config

I have been playing with the paginator function in Bolt CMS, it is easy to use.
Now I need to know if there is a way to implement the pagination in the contenttype yaml.
I think, is it possible something like this?
entries:
name: Entries
singular_name: Entry
fields:
...
taxonomy: [ categories ]
allowpaging: true
I only have found that you need explicity write the allowpaging flag when you fetch the content via setcontent:
{% setcontent entries = "entries/latest/4" allowpaging %}
But what if you want to use the same template for displaying the related taxonomy records? The problem is that you always will be fetching the last 4 entries regardless the taxonomy.
If there's no way to do this, there would be a way to implementing it?
Paging will also be automatically set if you use listing records setting
listing_records: 10
But your template still needs a pager that will use this setting - the listing templates in the theme/base-2014 will work and can be used as an example
The docs have more information https://docs.bolt.cm/contenttypes-and-records#defining-contenttypes
In config.yml set listing_records: xx or the number of records you want to show
then set in your .twix template {% setcontent entries = "entries/latest/xx" allowpaging %}with the same number
and add at the end of .twix file put this code {{ pager('pages') }} to show pages
You can see the official bolt docs for further informations
https://docs.bolt.cm/3.1/templating/content-paging

How to change the date format from the default type in Rails 2.0.2 using MySQL 5.1

I am looking for a way through which I could convert my default date format to a specific user format.
I am working on Rails 2.0.2. As we know on making use of the Scaffold command we automatically get the attributes of "id", "created_at" & "updated_at" as part of your table.
My scaffold command looks like this:-
script/server scaffold posts name:string title:string content:text
I am basically trying to implement a blog application. Now when I try to check the date when a particular blog is posted, I make use of the helper tags and through <%=h post.created_at %>in my index.html.erb file..
I am able to display the date a blog was originally created in default format which is currently like: Tue Jan 18 13:00:05 +0530 2011 via MySql 5.1 DB . I want to change this format to Month date Year.. like in the above case it would be January 18 2011.
In this regard could you please tell me how do I go about it. I am unsure of where do I need to make what changes.
Is there a way through which I can store the data in the index.html.erb and convert it then and there to the user defined format? I am not too sure of how to go about it directly from the view..
Also, I guess this, if hard coded would be a DRY(Don't Repeat Yourself) violation going against Rails principles. Could you suggest an appropriate way. Something that I can change as per a end user requirement.
Thank you..
You could use date_select_tag in the view and pass it in the time object and it would do the magic for you. Lets say for example, your time object is created at then,
<%= date_select_tag, :created_at, #user.created_at %>
Rails would take care of converting it back and forth..
Edit:
Also, you can convert it into date for views using #user.created_at.to_date.strftime() as documented here - http://www.ruby-doc.org/core/classes/Time.html#M000392
The way Rails handles date and time conversion formats is independent of which database you are using. To override the default format, you should add an initializer to your application. I have mine at config/initializers/time_formats.rb. Then in that file you would define the formats you want to use throughout the app:
Time::DATE_FORMATS[:just_date] = "%b %d, %Y"
Time::DATE_FORMATS[:just_time] = "%I:%M%p"
In order to use the new formats, you will pass the symbol to a string conversion like so:
<%= #post.created_at.to_s(:just_date) %>
You can use for example
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS
You can merge in your own (in environment.rb) for example
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:default => '%m/%d/%Y',
:date_time12 => "%m/%d/%Y %I:%M%p",
:date_time24 => "%m/%d/%Y %H:%M"
)