<![CDATA[ Using methods on the YAMS class - My Forums]]> https://forums.modx.com/thread/?thread=45479 <![CDATA[Re: Using methods on the YAMS class]]> https://forums.modx.com/thread/45479/using-methods-on-the-yams-class?page=2#dis-post-263217 Quote from: Roberto at Dec 17, 2009, 08:15 AM

Can you briefly explain how the yams parser works?
I’ve started to write some documentation on how the parser works... but that is probably too detailed for your requirements. You’ll probably find the YAMS placeholders documentation more useful for what you want.

Quote from: Roberto at Dec 17, 2009, 08:15 AM

With YAMS placeholder do I have only 1 query per page?
If you use the [tt](yams_data:...)[/tt] placeholder then you will have 1 database query per 50 [tt](yams_data:...)[/tt] placeholders. You can change this value by changing the constant called [tt]YAMS_DOC_LIMIT[/tt] that’s at the top of [tt]assets/modules/yams/class/yams.class.inc.php[/tt] if you wish. The larger it is, the more data it will grab from the database in one go, and the greater the memory requirements of the computer/server you are using - so there is some sort of compromise to be struck.

Quote from: Roberto at Dec 17, 2009, 11:23 AM

I can’t use YAMS placeholders, because in my snippet I need to check the values of the TVs.
I understand. I’m not sure how complicated your logic is, but if it is simple (if the placeholder output is empty then do one thing else do another for example) then you could continue to use the placeholder and use PHx for the logic. This may not be the best solution, but I thought I would mention it.

Quote from: Roberto at Dec 17, 2009, 11:23 AM

I can call via $modx->getTemplateVarOutput() only those TVs that contains decisional data, and use YAMS placeholders for the rest; at least my queries will be shortened.
Good idea.]]>
PaulSuckling Dec 17, 2009, 07:31 PM https://forums.modx.com/thread/45479/using-methods-on-the-yams-class?page=2#dis-post-263217
<![CDATA[Re: Using methods on the YAMS class]]> https://forums.modx.com/thread/45479/using-methods-on-the-yams-class?page=2#dis-post-263216
I can call via $modx->getTemplateVarOutput() only those TVs that contains decisional data, and use YAMS placeholders for the rest; at least my queries will be shortened.

Cheers,

Roberto]]>
Roberto Dec 17, 2009, 05:23 AM https://forums.modx.com/thread/45479/using-methods-on-the-yams-class?page=2#dis-post-263216
<![CDATA[Re: Using methods on the YAMS class]]> https://forums.modx.com/thread/45479/using-methods-on-the-yams-class?page=2#dis-post-263215
In these days I’ll implement it with YAMS placeholder.

Can you briefly explain how the yams parser works?

With YAMS placeholder do I have only 1 query per page?

Thanks,

Roberto]]>
Roberto Dec 17, 2009, 02:15 AM https://forums.modx.com/thread/45479/using-methods-on-the-yams-class?page=2#dis-post-263215
<![CDATA[Re: Using methods on the YAMS class]]> https://forums.modx.com/thread/45479/using-methods-on-the-yams-class?page=2#dis-post-263214 PaulSuckling Dec 16, 2009, 10:58 AM https://forums.modx.com/thread/45479/using-methods-on-the-yams-class?page=2#dis-post-263214 <![CDATA[Re: Using methods on the YAMS class]]> https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263213
Those calls are independent from using YAMS, I need them for the other TVs with "style" values for the blocks.

Do you have hints on how to minimize mysql server load? May getField can help me?]]>
Roberto Dec 16, 2009, 10:42 AM https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263213
<![CDATA[Re: Using methods on the YAMS class]]> https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263212 Quote from: Roberto at Dec 16, 2009, 03:10 PM

$templateVariables = $modx->getTemplateVarOutput(array(’introtext_’.$yamsId,’pagetitle_’.$yamsId),$id,1);
call will result in at least one mysql query, which can result in heavy load on the mysql server if there are lots of them. It is more efficient to use a yams_data placeholder because YAMS will consolidate all such placeholders and grab the required info from the database in a minimal number of queries.

(That was the reason for creating the placeholder in the firstplace. They are used internally by the YAMS Wayfinder templates and Ditto extension for efficiency.)]]>
PaulSuckling Dec 16, 2009, 10:09 AM https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263212
<![CDATA[Re: Using methods on the YAMS class]]> https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263211
Due to the fact that pagetitle_en and the others are TVs, I just used

$templateVariables = $modx->getTemplateVarOutput(array(’introtext_’.$yamsId,’pagetitle_’.$yamsId),$id,1);

and then, when I need it,

$templateVariables[’introtext_’.$yamsId];
$templateVariables[’pagetitle_’.$yamsId];

this bypasses both the YAMS and MODx parsers (at least I think so tongue).

I have already seen other problems, but not related to this; if I can’t figure them out, I’ll open new threads smiley

Cheers,

Roberto]]>
Roberto Dec 16, 2009, 09:10 AM https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263211
<![CDATA[Re: Using methods on the YAMS class]]> https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263210 Quote from: Roberto at Dec 16, 2009, 01:44 PM

I achieved the right selection of document variables by using a snippet call, for example

$YAMS_params = array(’get’ => ’data’, ’from’ => ’introtext’, ’docid’ => $id);
$introtext = $modx->runSnippet(’YAMS’, $YAMS_params);
That’s an excellent and simple idea. I don’t know why I hadn’t thought of doing that... Please let me know which technique you finally go for and why, since it would be good to capture this experience in the YAMS documentation.]]>
PaulSuckling Dec 16, 2009, 08:03 AM https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263210
<![CDATA[Re: Using methods on the YAMS class]]> https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263209
I achieved the right selection of document variables by using a snippet call, for example

$YAMS_params = array(’get’ => ’data’, ’from’ => ’introtext’, ’docid’ => $id);
$introtext = $modx->runSnippet(’YAMS’, $YAMS_params);

so I don’t have to pass anything to my snippet.

As long as I wipe out parameters from my snippet (there are a few now), I could use [[YAMS? &get=`csnippet` &from=`mySnippet`]]

(having mySnippet_en, mySnippet_it) and get it right with my old snippet, I guess.

Now I’m going to see which solution better fits this...

Thanks,

Roberto]]>
Roberto Dec 16, 2009, 07:44 AM https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263209
<![CDATA[Re: Using methods on the YAMS class]]> https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263208
Within your snippet you can use the [tt]$yamsId[/tt] variable to access language specific chunks/templates etc: [tt]’chunkname_’ . $yamsId [/tt].

Don’t forget that you can also output yams_data placeholders too: [tt]((yams_data:docId:fieldname))[/tt].

This works a little bit like the GetField snippet in that it allows you to output tvs from specified documents. So you could output a placeholder like so: [tt]’((yams_data:’ . $docId . ’:pagetitle_’ . $yamsId . ’))’[/tt] to get the correct language pagetitle for document [tt]$docId[/tt].

See the YAMS placeholder documentation for more details.]]>
PaulSuckling Dec 15, 2009, 04:33 PM https://forums.modx.com/thread/45479/using-methods-on-the-yams-class#dis-post-263208