I applogize if this topic is already convered. I spent few days and still can't figure out how to do this. I need to pass mediaID of a folder and get all children and send back JSON. This is happening, but i need to pass "tags" in the URL too. That is where i'm lost. Please help me. Here is what i have in XSLT and works great without filtering by the field i have on each Image "tags". I need to modify the below "select" for GetMedia to accept "tags" and only return images that has a tag matching what i'm passing.
<xsl:variable name="pageId" select="umbraco.library:Request('pageid')" /> xsl:variable name="mediaId" select="umbraco.library:Request('mediaid')" /> <xsl:template match="/"> <xsl:choose> <!-- Make sure pageId is not empty --> <xsl:when test="normalize-space($pageId)"> <!-- Get the page --> <xsl:variable name="page" select="umbraco.library:GetXmlNodeById($pageId)" /> <!-- Output the page as JSON --> <xsl:value-of select="orc.XSLToJSON:XmlToJson($page)" disable-output-escaping="yes" />
</xsl:when> <!-- Make sure mediaID is not empty --> <xsl:when test="normalize-space($mediaId)"> <!-- Get the media --> <xsl:variable name="media" select="umbraco.library:GetMedia($mediaId,true())" /> <!-- Output the media as JSON --> <xsl:value-of select="orc.XSLToJSON:XmlToJson($media)" disable-output-escaping="yes" />
Have you defined and selected the tags on each of the images? And what does your JSON output currently look like? And what does the XML in fact return?
Thank you Jan for getting back to me. Yes "tags" field is created and all images (three under the folder 1061) has tags in them. Here is what i see in the browser when it returns json. One folder is "Wedding", it has one image, then it has another folder "Chris & Rebecca" that has two images.
in addition, i was thinking maybe i write my own SQL to get cmsContentXml back. but not working with my tags argument. It does not show my nice folder structure as above.
<xsl:when test="normalize-space($mediaId2)"> <!-- Get the media --> <xsl:variable name="media"> <sql> <commandtype>text</commandtype> <!--<commandtext><![CDATA[select top 5 * from umbracoNode where trashed=@filter]]></commandtext>--> <commandtext><![CDATA[select * from cmsContentXml where xml like '%<tags>%MoMo%']]></commandtext> <!--<parameter name="@filter">0</parameter>--> </sql> </xsl:variable> <!-- Output the media as JSON --> <xsl:value-of select="orc.XSLToJSON:XmlToJson(SqlHelper:ExecuteDataset($media)//root)" /> </xsl:when>
umbraco.library.GetMedia() by tags
I applogize if this topic is already convered. I spent few days and still can't figure out how to do this. I need to pass mediaID of a folder and get all children and send back JSON. This is happening, but i need to pass "tags" in the URL too. That is where i'm lost. Please help me. Here is what i have in XSLT and works great without filtering by the field i have on each Image "tags". I need to modify the below "select" for GetMedia to accept "tags" and only return images that has a tag matching what i'm passing.
http://MyDomain.com/json?mediaid=1061&tag=Party
<xsl:variable name="pageId" select="umbraco.library:Request('pageid')" />
xsl:variable name="mediaId" select="umbraco.library:Request('mediaid')" />
<xsl:template match="/">
<xsl:choose>
<!-- Make sure pageId is not empty -->
<xsl:when test="normalize-space($pageId)">
<!-- Get the page -->
<xsl:variable name="page" select="umbraco.library:GetXmlNodeById($pageId)" />
<!-- Output the page as JSON -->
<xsl:value-of select="orc.XSLToJSON:XmlToJson($page)" disable-output-escaping="yes" />
</xsl:when>
<!-- Make sure mediaID is not empty -->
<xsl:when test="normalize-space($mediaId)">
<!-- Get the media -->
<xsl:variable name="media" select="umbraco.library:GetMedia($mediaId,true())" />
<!-- Output the media as JSON -->
<xsl:value-of select="orc.XSLToJSON:XmlToJson($media)" disable-output-escaping="yes" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="orc.XSLToJSON:XmlToJson($currentPage)" />
</xsl:otherwise>
</xsl:choose>
Hi Mohammad
Have you defined and selected the tags on each of the images? And what does your JSON output currently look like? And what does the XML in fact return?
/Jan
Thank you Jan for getting back to me. Yes "tags" field is created and all images (three under the folder 1061) has tags in them. Here is what i see in the browser when it returns json. One folder is "Wedding", it has one image, then it has another folder "Chris & Rebecca" that has two images.
{"Folder":{"@id":"1061","@version":"2f01954f-dc8f-4870-a4c1-da1285304e9f","@parentID":"-1","@level":"1","@writerID":"0","@nodeType":"1031","@template":"0","@sortOrder":"1","@createDate":"2013-01-25T11:29:48","@updateDate":"2013-01-25T11:29:48","@nodeName":"Wedding","@urlName":"wedding","@writerName":"admin","@nodeTypeAlias":"Folder","@path":"-1,1061","contents":null,"Image":{"@id":"1062","@version":"1e7f0445-cac5-465d-a6a1-a059a5fa05dc","@parentID":"1061","@level":"2","@writerID":"0","@nodeType":"1032","@template":"0","@sortOrder":"0","@createDate":"2013-01-25T11:30:20","@updateDate":"2013-01-25T21:47:34","@nodeName":"Arab Sheikh","@urlName":"arabsheikh","@writerName":"admin","@nodeTypeAlias":"Image","@path":"-1,1061,1062","umbracoFile":"/media/16/Arab_Sheikh.jpg","umbracoWidth":"1936","umbracoHeight":"2592","umbracoBytes":"2617917","umbracoExtension":"jpg","tags":"MoMo,Arab,Dress"},"Folder":{"@id":"1070","@version":"aa0ec9e7-0a26-41d0-8f5b-f341cbb3f411","@parentID":"1061","@level":"2","@writerID":"0","@nodeType":"1031","@template":"0","@sortOrder":"0","@createDate":"2013-01-25T19:42:37","@updateDate":"2013-01-25T19:42:37","@nodeName":"Chris & Rebecca","@urlName":"chris&rebecca","@writerName":"admin","@nodeTypeAlias":"Folder","@path":"-1,1061,1070","contents":null,"Image":[{"@id":"1068","@version":"e22aff90-a113-4352-b5a4-09f8bc9484ca","@parentID":"1070","@level":"3","@writerID":"0","@nodeType":"1032","@template":"0","@sortOrder":"1","@createDate":"2013-01-25T13:15:44","@updateDate":"2013-01-25T19:46:23","@nodeName":"Photo 1","@urlName":"photo1","@writerName":"admin","@nodeTypeAlias":"Image","@path":"-1,1061,1070,1068","umbracoFile":"/media/56/photo_1.JPG","umbracoWidth":"574","umbracoHeight":"768","umbracoBytes":"72588","umbracoExtension":"JPG","tags":"Cape Cod,Dana,Mohammad,Shopping"},{"@id":"1069","@version":"d43d34bc-fb34-4ac1-993d-73d51355f0df","@parentID":"1070","@level":"3","@writerID":"0","@nodeType":"1032","@template":"0","@sortOrder":"2","@createDate":"2013-01-25T13:15:46","@updateDate":"2013-01-25T18:53:14","@nodeName":"Photo 2","@urlName":"photo2","@writerName":"admin","@nodeTypeAlias":"Image","@path":"-1,1061,1070,1069","umbracoFile":"/media/61/photo_2.JPG","umbracoWidth":"1024","umbracoHeight":"768","umbracoBytes":"69382","umbracoExtension":"JPG","tags":"MoMo,Dana,Sand Tour"}]}}}
You can use jsonLint.com and use this URL for above example: http://techvall.w11.wh-2.com/json?mediaid=1061
in addition, i was thinking maybe i write my own SQL to get cmsContentXml back. but not working with my tags argument. It does not show my nice folder structure as above.
http://techvall.w11.wh-2.com/json?mediaid2=1061 [notice the mediaid2 argument]
<xsl:when test="normalize-space($mediaId2)">
<!-- Get the media -->
<xsl:variable name="media">
<sql>
<commandtype>text</commandtype>
<!--<commandtext><![CDATA[select top 5 * from umbracoNode where trashed=@filter]]></commandtext>-->
<commandtext><![CDATA[select * from cmsContentXml where xml like '%<tags>%MoMo%']]></commandtext>
<!--<parameter name="@filter">0</parameter>-->
</sql>
</xsl:variable>
<!-- Output the media as JSON -->
<xsl:value-of select="orc.XSLToJSON:XmlToJson(SqlHelper:ExecuteDataset($media)//root)" />
</xsl:when>
thank you so much
Mohammad
is working on a reply...