Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Grabbing date format string from an attribute? (Read 1215 times)
Scott Heftler
Full Member
*
Offline



Posts: 33

Grabbing date format string from an attribute?
Dec 10th, 2015, 5:30pm
 
Greetings. I've spent the last two hours trying every conceivable permutation of eval, value, and do in order to use a string attribute as a date format string.

For example, this obviously works:

^value($blogDate.format("MM d, y"))^

But let's say I want to grab that format string from an attribute. †Let's say I have "MM d, y" stored inside a dedicated variable storage note, bstVAR, as $tmpStr1.

None of these or their kin have worked:

<p>1 = ^value($blogDate.format("eval($tmpStr1(bstVAR))"))^
<p>2 = ^value($blogDate.format("^do(_date)^"))^
<p>3 = ^value($blogDate.format("^do(_date2)^"))^
<p>4 = ^value(^do(_date3)^)^

Macros used above:

_date †= ^value($tmpStr1(bstVAR))^
_date2 = eval($tmpStr1(bstVAR))
_date3 = $blogDate.format(eval($tmpStr1(bstVAR))

Does anyone know how I might pass the date format string from an attribute?
Back to top
 
« Last Edit: Dec 10th, 2015, 7:51pm by Scott Heftler »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: grabbing date format string from an attribute?
Reply #1 - Dec 10th, 2015, 6:40pm
 
.format() date-formatting string work on date objects.  If you store a date as a string, it isn't a Date-type object with all that flows from that.

Suggestions, store your date in a date-type attribute and (not tested) the problem should not occur.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Scott Heftler
Full Member
*
Offline



Posts: 33

Re: grabbing date format string from an attribute?
Reply #2 - Dec 10th, 2015, 7:06pm
 
Hi Mark! Thanks for your reply.

$blogDate actually is a date-type attribute. †The problem isnít coercing from the date-type object, but in getting Tinderbox to inject a string inside the ( ) from a variable. †That is, Iím not having trouble with $blogDate.format(ďMM d, y") but with $blogDate.format($myString).

What Iím trying to do is let the user enter a date format string as a key attribute. †I want the date format inside my export template to be defined by the user. †But Iím having trouble doing this with the .format( ) operator.
Back to top
 
 
  IP Logged
Scott Heftler
Full Member
*
Offline



Posts: 33

Re: grabbing date format string from an attribute?
Reply #3 - Dec 10th, 2015, 7:50pm
 
Got it! †Finally.

I have to use the format(data, ďformatStringĒ) operator! †Not the .format( ) operator.

Success: the user can modify the date format for a NOTE and this will determine the formate of the date during export. †The NOTE string value looks like this because I want the date to actually show up as the display name of the NOTE:

date("today").format("MM d, y")

The export code that pulls it off:

^action($tmpStr1(bstVAR)=$DisplayExpression(dashDate).split("format").at(1).repl
ace('(\"|\(|\))',""))^
<p class="post-meta">^value(format($blogDate,$tmpStr1(bstVAR)))^</p>


So given that the $DisplayExpression of note dashDate looks like this:

date("today").format("MM d, y")

then the following two lines will have the same export:

<p class="post-meta">^value($blogDate.format("MM d, y"))^</p>
<p class="post-meta">^value(format($blogDate,$tmpStr1(bstVAR)))^</p>


Whew Ö
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Grabbing date format string from an attribute?
Reply #4 - Dec 11th, 2015, 5:27am
 
Apologies for my misunderstanding. The original seems to work for me. I've added Date attribute $blogDate and String attribute $tmpStr1 to 2 notes, 'Test' and 'bstVAR'. In both I've set the $bldDate to "today" and the $tmpStr1 to "MM d, y". The test note has the template:

<p>^value($blogDate)</p>
<p>^value($blogDate.format("MM d, y"))</p>
<p>^value($blogDate.format($tmpStr1))</p>
<p>^value($blogDate.format($tmpStr1("bstVAR")))</p>


The HTML rendering is this:

<p>11/12/2015, 09:25</p>
<p>December 11, 2015</p>
<p>December 11, 2015</p>
<p>December 11, 2015</p>


As expected, the first <p> has the wrong format as it has not format string. Also, is it the format (noticed during testing) if we don't provide a vlaid date string.

Anyway the fourth <p> shows that your original desired method does work - or at least does for me. †Likely there're something else at play in your file that's causing the original code to fail.

Going further, I made a $strA of "mm", $strB of "D" and $strC of "YY" and then used export:

<p>^value($blogDate.format($strA.uppercase+$strB.lowercase+", "+$strC.substr(0,1).lowercase))^</p>

The result? Still <p>December 11, 2015</p>

My test file is here (zip) so you can check the code against yours.
Back to top
 
« Last Edit: Dec 18th, 2015, 3:36am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Grabbing date format string from an attribute?
Reply #5 - Dec 11th, 2015, 11:50am
 
This should be very easy!

Letís store the desired format, "M" (the month) in $MyString.  The rule

    $Name=$Created.format($MyString)

will rename the note to the abbreviated month of the noteís creation, and when exporting

    ^value( $Created.format($MyString) )

will export "Dec" if the note was created in December.
Back to top
 
 
WWW   IP Logged
Scott Heftler
Full Member
*
Offline



Posts: 33

Re: Grabbing date format string from an attribute?
Reply #6 - Dec 17th, 2015, 6:55pm
 
My God. Iíve used the following and it works:

<p class="post-meta">^value($blogDate.format($tmpStr1(bstVAR)))^</p>

... where the string is set via:

^action($tmpStr1(bstVAR)=$DisplayExpression(dashDate).split("format").at(1).repl
ace('(\"|\(|\))',""))^


This must be one of those cases where something else was the bug and I ascribed it to the wrong cause and made an multi-hour project out of non-problem.

Thanks Marks!
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print