(2016-01-21, 18:02)BobCratchett Wrote: [ -> ]@Mr. V - can you please test this branch for initial support of variables in templates.
It adds a new section to the 'Other' templates for your variables, within which you can use any $SKINSHORTCUTS properties you like:-
The full <variable /> element is required each time - Skin Shortcuts will take care of combining these across multiple templates. I don't really have a use-case for this myself and as such I've only done sanity checks, so can you please test not only that it works, but that it does what you need
Cheers.
Hi Bob, Thanks for the addition.
In my template
Code:
<other include="widgetvars">
<condition tag="property" attribute="name|widgetArt">FanArt</condition>
<property name="id" tag="mainmenuid" />
<controls>
</controls>
<variables>
<variable name="HomeWidget8011$SKINSHORTCUTS[id]FanArtVar">
<value condition="!IsEmpty(Container(8011$SKINSHORTCUTS[id]).ListItem.Art(fanart))">$INFO[Container(8011$SKINSHORTCUTS[id]).ListItem.Art(fanart)]</value>
<value>$INFO[Container(8011$SKINSHORTCUTS[id]).ListItem.Art(thumb)]</value>
</variable>
</variables>
</other>
Written in the includes
Code:
<variable name="HomeWidget80111FanArtVar">
<value condition="StringCompare(System.ProfileName,Master user) + [!IsEmpty(Container(80111).ListItem.Art(fanart))]">$INFO[Container(80111).ListItem.Art(fanart)]</value>
<value condition="StringCompare(System.ProfileName,Master user)">$INFO[Container(80111).ListItem.Art(thumb)]</value>
</variable>
A few things to report;
1. If I don't include <controls></controls> tags skinshort cuts will not build the menu. In the logs I get this
Code:
13:37:39 T:15128 DEBUG: script.skinshortcuts: Building menu for profile Master user
13:37:40 T:15128 DEBUG: script.skinshortcuts: Failed to write menu
13:37:40 T:15128 ERROR: Traceback (most recent call last):
13:37:40 T:15128 ERROR: File "C:\Kodi\portable_data\addons\script.skinshortcuts\resources\lib\xmlfunctions.py", line 93, in buildMenu
13:37:40 T:15128 ERROR: self.writexml( profilelist, mainmenuID, groups, numLevels, buildMode, progress, options, minitems )
13:37:40 T:15128 ERROR: File "C:\Kodi\portable_data\addons\script.skinshortcuts\resources\lib\xmlfunctions.py", line 586, in writexml
13:37:40 T:15128 ERROR: Template.parseItems( "mainmenu", 0, templateMainMenuItems, profile[ 2 ], profile[ 1 ], "", "", mainmenuID )
13:37:40 T:15128 ERROR: File "C:\Kodi\portable_data\addons\script.skinshortcuts\resources\lib\template.py", line 104, in parseItems
13:37:40 T:15128 ERROR: self.findOther( item, profile, profileVisibility, visibilityCondition )
13:37:40 T:15128 ERROR: File "C:\Kodi\portable_data\addons\script.skinshortcuts\resources\lib\template.py", line 311, in findOther
13:37:40 T:15128 ERROR: textVersion = xmltree.tostring( template.find( "controls" ), encoding='utf8' )
13:37:40 T:15128 ERROR: File "C:\Kodi\system\python\Lib\xml\etree\ElementTree.py", line 1126, in tostring
13:37:40 T:15128 ERROR: ElementTree(element).write(file, encoding, method=method)
13:37:40 T:15128 ERROR: File "C:\Kodi\system\python\Lib\xml\etree\ElementTree.py", line 817, in write
13:37:40 T:15128 ERROR: self._root, encoding, default_namespace
13:37:40 T:15128 ERROR: File "C:\Kodi\system\python\Lib\xml\etree\ElementTree.py", line 876, in _namespaces
13:37:40 T:15128 ERROR: iterate = elem.getiterator # cET compatibility
13:37:40 T:15128 ERROR: AttributeError: 'NoneType' object has no attribute 'getiterator'
2. The condition i have setup is to check for fanart. I have three menu items where the 'widgetArt' attribute is set to 'FanArt' It only writes the variable for the first one it finds.
3. I am not to keen on 'StringCompare(System.ProfileName,Master user)' being written in the condition. As my widget code is quite complex, if were to use this method of variables It would write hundreds of variables. Thats a lot of string compares and I would be concerned that it would impact performance on lower powered devices.
It seems like if any of the conditions change skin short cuts will re-code the include file, so I cant imagine that a variable needs to be specific to a user. Different user may have different widget setups but all that would mean is on change of the user, the template would be rewritten with slight variable changes.
4. I haven't tested this out yet but a potential issue could be the [..... ] added around the condition. If you had more complex conditions it may not play so nice.
I would like to be able to code it like this;
Code:
<other include="widgetvars">
<condition tag="property" attribute="name|widgetArt">FanArt</condition>
<property name="id" tag="mainmenuid" />
<variables>
<variable name="HomeWidget8011$SKINSHORTCUTS[id]FanArtVar">
<value condition="!IsEmpty(Container(8011$SKINSHORTCUTS[id]).ListItem.Art(fanart))">$INFO[Container(8011$SKINSHORTCUTS[id]).ListItem.Art(fanart)]</value>
<value>$INFO[Container(8011$SKINSHORTCUTS[id]).ListItem.Art(thumb)]</value>
</variable>
</variables>
</other>
And say if I has 3 menu items with fanart it would output as so;
Code:
<variable name="HomeWidget80111FanArtVar">
<value condition="!IsEmpty(Container(80111).ListItem.Art(fanart))]">$INFO[Container(80111).ListItem.Art(fanart)</value>
<value>$INFO[Container(80111).ListItem.Art(thumb)]</value>
</variable>
<variable name="HomeWidget80112FanArtVar">
<value condition="!IsEmpty(Container(80112).ListItem.Art(fanart))]">$INFO[Container(80112).ListItem.Art(fanart)</value>
<value>$INFO[Container(80112).ListItem.Art(thumb)]</value>
</variable>
<variable name="HomeWidget80113FanArtVar">
<value condition="!IsEmpty(Container(80113).ListItem.Art(fanart))]">$INFO[Container(80113).ListItem.Art(fanart)</value>
<value>$INFO[Container(80113).ListItem.Art(thumb)]</value>
</variable>
I must say great work though. Kodi reads the variable written in the includes without an issue.