[pmwiki-users] One more was Re: I want to use FmtPV from mackup to set Page Variable, but can't get it to work reliably

Petko Yotov 5ko at 5ko.fr
Fri Jul 14 16:43:12 CDT 2017


The way I wrote it, the function CCGetVariable will only be called if 
{$mymarkupvar} is in the page, and inside your function you can contact 
the external service only if your keyword is among the page properties.

This doesn't prevent you to additionally do some caching, eg only 
contact the external service once an hour/day/period and in the mean 
time show the cached values.

Petko

---
Change log     :  http://www.pmwiki.org/wiki/PmWiki/ChangeLog
Release notes  :  http://www.pmwiki.org/wiki/PmWiki/ReleaseNotes
If you upgrade :  http://www.pmwiki.org/wiki/PmWiki/Upgrades


On 2017-07-14 23:08, Christopher Cox wrote:
> My problem is that what I want to set is a bit expensive (involves
> some external web services).  So I was looking for a way to set it
> only if a piece of markup was done on a page.  I'd like to leave in
> the user's hands rather than hardcode exceptions or limit to specific
> groups or pages.
> 
> Thanks for all the tips and info on this though!
> 
> My original thought was to use some new markup rather than the
> InterMap, I may still pursue that route.  Ultimately, I may create my
> own InterMap like thing that takes this and formats for the full URL
> with my PageVariable in it....  I still want the PageVariable for
> cases outside of this.
> 
> |
> |
> 
> |workspace://SpacesStore/a4757c91-8291-4b2f-9e6c-bff38fbed25b|
> 
> 
> On 07/14/2017 03:09 PM, Petko Yotov wrote:
>> Oh, InterMap definitions are processed even before any markup rules, 
>> so your markup rule has not been able to set the PageVariable.
>> 
>> Using a markup rule is not a great way to set a PageVariable. I'd use 
>> a $FmtPV function instead. See/check how other PageVariables are 
>> defined as functions in the core (pmwiki.php:123) eg $Groupspaced, 
>> $Title, $BaseName or $PasswdRead. See how the page group, name or 
>> another attribute is passed, and think how your variable will work for 
>> another page like {OtherGroup.OtherPage$mymarkupvar}. It is complex 
>> and resource intensive, but possible to RetrieveAuthPage the pagename, 
>> then to look for your markup in the $page['text'] entry.
>> 
>> Or, piggyback on an existing PageVariable if it is never used, eg. 
>> (:keywords:) or (:description:), and have your markup to set this 
>> variable by a simple replacement:
>> 
>>   # Convert (:mymarkup:) to (:keywords ccox:myvariable:).
>>   # When a page is saved, "ccox:myvariable" will be in
>>   # the 'keywords' property and in $page["keywords"]
>>   Markup('mymarkupvar', '<keywords', '/\\(:mymarkup:\\)/', '(:keywords 
>> ccox:myvariable:)');
>> 
>>   # a better way to set the PageVariable
>>   $FmtPV['$mymarkupvar'] = 'CCGetVariable(@$page["keywords"])';
>> 
>>   function CCGetVariable($keywords) {
>>     if(preg_match('/ccox:myvariable/i', $keywords)) return 'hello';
>>   }
>> 
>> This will also populate the "meta keywords" tag in the HTML source of 
>> the page with "ccox:myvariable". If this is unacceptable, select a 
>> different way (see/copy how the keywords property is set in 
>> stdmarkup.php, and add an entry to $SaveProperties).
>> 
>> Petko
>> 
>> 
>> On 2017-07-14 20:45, Christopher Cox wrote:
>>> Let's say I now want to use a InterMap on such a page with my page
>>> variable populated via markup...
>>> 
>>> such that I want to have
>>> 
>>> myintermap:    http://example.com/$1?a={$mymarkupvar}
>>> 
>>> 
>>> The variable doesn't populate in that one.  Is it possible?
>>> 
>>> 
>>> On 07/14/2017 01:15 PM, Christopher Cox wrote:
>>>> Bingo! Thanks Petko! '<{$var}'
>>>> 
>>>> 
>>>> On 07/14/2017 12:59 PM, Petko Yotov wrote:
>>>>> When the markup rules are processed one after another, 
>>>>> PageVariables like {$mymarkupvar} are replaced with their contents 
>>>>> very early. Most other markup rules are processed later, see 
>>>>> pmwiki.php?action=ruleset. So your page variable is not yet set 
>>>>> when it is encountered in the page, and it is replaced with 
>>>>> nothing, empty string.
>>>>> 
>>>>> MarkupMarkup, ie (:markup:) rules are processed before most other 
>>>>> rules, and before PageVariables. The content of a (:markup:) block 
>>>>> is passed through all markup rules one after another, like for the 
>>>>> page, but before the page. At that point, if you encounter your 
>>>>> markup rule, it will set the page variable (but not display it in 
>>>>> the same block). However, later, when the rest of the page is 
>>>>> processed, the page variable value is already set so when your 
>>>>> markup is encountered, the variable is replaced with the value.
>>>>> 
>>>>> If you must process your markup rule before {$PageVariables}, 
>>>>> change the "when" argument (second) on the Markup() call.
>>>>> 
>>>>> Petko
>>>>> 
>>>>> ---
>>>>> 
>>>>> On 2017-07-14 19:45, Christopher Cox wrote:
>>>>>> Ok.. this is weird.  If my (:mymarkup:) is embedded in
>>>>>> (:markup:)(:markupend:) it works and my page variable is set. What 
>>>>>> am
>>>>>> I missing?
>>>>>> 
>>>>>> 
>>>>>> On 07/14/2017 11:45 AM, Christopher Cox wrote:
>>>>>>> What I want is to have something like:
>>>>>>> 
>>>>>>> 
>>>>>>> (:mymarkup:)
>>>>>>> 
>>>>>>> {$mymarkupvar}
>>>>>>> 
>>>>>>> 
>>>>>>> on a page.  Where mymarkup does inside it's function:
>>>>>>> 
>>>>>>> 
>>>>>>> global $FmtPV;
>>>>>>> 
>>>>>>> 
>>>>>>> $GLOBALS['myvar'] = 'hello';
>>>>>>> 
>>>>>>> $FmtPV['$mymarkupvar'] = '$GLOBALS["myvar"]';



More information about the pmwiki-users mailing list