Help with ForEachTiddler - take 2

81 views
Skip to first unread message

magev958

unread,
Feb 28, 2012, 7:04:02 AM2/28/12
to TiddlyWiki
Hi, a long time ago I got some help with the code to get a one line of
the tiddler content in an FET-list -
http://groups.google.com/group/tiddlywiki/browse_frm/thread/72450492805721f0?hl=en&tvc=1

<<forEachTiddler
where
'tiddler.tags.contains("information")'
sortBy
'store.getValue(tiddler,"created")'
descending
script
'
function getFirstLine(s) {
var m = s.match(/\s*(.*)/);
return m != null && m.length >= 1 ? m[1] : "";
}
' write
'(index < 5) ? "[["+tiddler.title+"]] - "+tiddler.creator+" -
"+tiddler.created+" - "+getFirstLine(tiddler.text)+"\n" : ""'>>

My question this time is if I can get different formating depending on
tag? For example if I have "priority1", "priority2", "priority3", can
I get "priority2" with a red border and "priority3" with a yellow
background?

Thanks in advance/

cmari

unread,
Feb 28, 2012, 7:35:33 AM2/28/12
to tiddl...@googlegroups.com
While this is not an fET-specific answer, maybe what you want is Tobias's ColoredLinksPlugin?
http://coloredlinks.tiddlyspot.com/#Welcome
cmari

Måns

unread,
Feb 28, 2012, 12:39:42 PM2/28/12
to TiddlyWiki
Hi magev958

> My question this time is if I can get different formating depending on
> tag? For example if I have "priority1", "priority2", "priority3", can
> I get "priority2" with a red border and "priority3" with a yellow
> background?

Maybe you are asking for some kind of HideWhenPlugin for fET-
listitems...

I use this workaround inside a fET call (after "write"):

"+(tiddler.tags.contains("SomeTag")?"<<tiddler
SomeOtherTiddlerWithTemplate with:[[" + tiddler.title+"]]\>\>":"")+"

The effect is that the transcluded tiddler
"SomeOtherTiddlerWithTemplate" is only visible if [[" + tiddler.title
+"]] is tagged with "SomeTag"...

Works for me...

Cheers Måns Mårtensson

Eric Shulman

unread,
Feb 28, 2012, 1:22:16 PM2/28/12
to TiddlyWiki
On Feb 28, 4:04 am, magev958 <magnus.ev...@gmail.com> wrote:
> Hi, a long time ago I got some help with the code to get a one line of
> the tiddler content in an FET-list -http://groups.google.com/group/tiddlywiki/browse_frm/thread/724504928...
>
> <<forEachTiddler
>  where
>  'tiddler.tags.contains("information")'
>  sortBy
>  'store.getValue(tiddler,"created")'
>  descending
>  script
>  '
>  function getFirstLine(s) {
>  var m = s.match(/\s*(.*)/);
>  return m != null && m.length >= 1 ? m[1] : "";
>  }
>  ' write
>  '(index < 5) ? "[["+tiddler.title+"]] - "+tiddler.creator+" -
> "+tiddler.created+" - "+getFirstLine(tiddler.text)+"\n" : ""'>>
>
> My question this time is if I can get different formating depending on
> tag? For example if I have "priority1", "priority2", "priority3", can
> I get "priority2" with a red border and "priority3" with a yellow
> background?

You could wrap the output in CSS styles (i.e.,
"@@attr:value;attr:value;...content...@@"), based on the tag value.
First, in the "script" clause of your FET, add a new function
definition following the closing "}" of getFirstLine:

function getStyle(t) {
if (t.isTagged("priority1")) return "text:normal";
if (t.isTagged("priority2")) return "border:red";
if (t.isTagged("priority3")) return "background-color:yellow";
}

Then, in the "write" clause of the FET, add the enclosing CSS syntax
and invoke getStyle(), like this:

'(index < 5) ? "@@"+getStyle(tiddler)+";[["+tiddler.title+"]] -
"+tiddler.creator+" - "+tiddler.created+" -
"+getFirstLine(tiddler.text)+"@@\n" : ""'

Producing output like this (using "priority2 as an example):

@@border:red;[[SomeTitle]] - CreatorName - date - ...first line...@@

That should do it.

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

----
WAS THIS ANSWER HELPFUL? IF SO, PLEASE MAKE A DONATION
http://www.TiddlyTools.com/#Donations
note: donations are directly used to pay for food, rent,
gas, net connection, etc., so please give generously and often!

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:
http://www.TiddlyTools.com/#Contact

magev958

unread,
Feb 29, 2012, 7:54:01 AM2/29/12
to TiddlyWiki
Guys, I'm constantly amazed of your ingenuity!

Thanks!
/Magnus

Cyrill

unread,
Mar 3, 2012, 7:04:15 AM3/3/12
to tiddl...@googlegroups.com
Hello,

someone able for a testcase, car I get an error by applying the code of Eric ...

Best Regards
Reply all
Reply to author
Forward
0 new messages