Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Insert date in static html webpart or template layout View modes: 
User avatar
Member
Member
zelewsky-lbpc - 6/17/2010 12:51:57 PM
   
Insert date in static html webpart or template layout
I want to add the year within the boilerplate language in my footer so the year is dynamic and won't have to be changed Dec. 31 to show 2011 on Jan. 1. I know I can use the DateTime web part and CSS to display it all inline to accomplish this, but there are a couple of other instances where I want to add a date without using the web part.

Within a static html web part I want to add code along the lines of the following:

<p class=copyright">© {%# <%response.write(Year(Date)) %} by My Company. All rights reserved.</p>


I'd also like to be able to insert the date on a newsletter template without using the DateTime webpart because the date gets knocked out when the html is emailed.




User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 6/22/2010 6:02:53 AM
   
RE:Insert date in static html webpart or template layout
Hello,

You can create custom macro for that purpose, which is described here in our Developer's Guide: http://devnet.kentico.com/docs/devguide/appendix_a___macro_expressions.htm

You can grab exactly the code from there and use it like this:

{#CurrentTime#}

This custom macro can be then used in your Static HTML webpart and Newsletter template as well.

Best regards
Ondrej Vasil

User avatar
Member
Member
perezj-gmail - 6/30/2010 8:23:51 PM
   
RE:Insert date in static html webpart or template layout
I have been using Custom Macros in the Template layout without any problems until I upgraded to Version 5.5 today.

Now I get this error in when in the Design Tab in the CMSDesk.

Error:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

This is in the footer of the template layout. Removing the Macros for the href works just fine.

<li><a href="<%= CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros( "{#ancestor|BBBUrl|https://www.bbb.org/online/consumer/cks.aspx?id=109081111523#}" ) %>" target="_blank" class="bbb" title="Click to verify BBB accreditation and to see a BBB report.">Better Business Bureau</a></li>

I can't use an Inline control to provide the value, is there any other control that I can use to provide the value of the "BBBUrl" that is coming from the doctype?

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 7/8/2010 4:33:58 AM
   
RE:Insert date in static html webpart or template layout
Hi,

The code itself is correct. You can try to create simple page template without any web parts and add the code into layout of the page template and you will see that it will work just fine. I have tested to code in Kentico CMS 5.5 and it does not produce any exceptions. It seems to me that you are using some custom web parts on your problematic page template which are responsible for this behavior.

Could you please try to disable/remove your custom web parts one by one and check the behavior?
You can also create custom web part which will output your code.

Best regards,
Miroslav Remias.

User avatar
Member
Member
adi-wellness-layers - 2/21/2011 8:14:22 AM
   
RE:Insert date in static html webpart or template layout
How can i insert a format date field of the current document to the Static HTML?

i want to print the follwing field:
{%currentdocument.publishDate%}

in the following format:
M/d/yyyy


Thanks,
Adi

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 3/15/2011 10:55:02 PM
   
RE:Insert date in static html webpart or template layout
Hi,

You can use (format) parameter of the macro expression, like described at
DevGuide appendix - Macros
You will also need to type the value to the correct type.

In your case it could look like:

{%currentdocument.publishDate|(todatetime)|(format){0:M/d/yyyy}%}

Hope this helps.

Regards,
Zdenek