Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jason N 55 posts 79 karma points
    Jun 03, 2011 @ 21:41
    Jason N
    0

    Finding documents by tag

    I'm trying to find documents of a particular type with specific tags.  So far I haven't been able to figure out how to do this with razor.  I tried the following and it returned one object, but it should have returned about twenty.

    Model.Descendants("BlogPost").Where("tags.Contains(\"" + tagName + "\")");

    I also tried 

    umbraco.cms.businesslogic.Tags.Tag.GetDocumentsWithTags(tagName);

    But that doesn't return the DynamicNode type that I need.  Help!

     

     

  • Toni Becker 146 posts 425 karma points
    Jun 05, 2011 @ 22:44
    Toni Becker
    0

    Hy Jason. If you want a solution or an input for development you could have a look at the ublogsy project. it's very straight forward handling tags and the other stuff. The best thing it's completely written in razor.

  • Toni Becker 146 posts 425 karma points
    Jun 05, 2011 @ 22:47
    Toni Becker
    0

    for another try post some of the content from your umbraco.config xml. than i think we can help you out. greetings toni

  • Jason N 55 posts 79 karma points
    Jun 07, 2011 @ 17:19
    Jason N
    0
            <!-- what file extension that should cause umbraco to create thumbnails -->
    
    <?xml version="1.0" encoding="utf-8" ?>
    <settings>
        <content>
            <imaging>
                <!-- what file extension that should cause umbraco to create thumbnails -->
                <imageFileTypes>jpeg,jpg,gif,bmp,png,tiff,tif</imageFileTypes>
                <!-- what attributes that are allowed in the editor on an img tag -->
                <allowedAttributes>alt,border,class,style,align,id,name,onclick,usemap</allowedAttributes>
            </imaging>
            <scripteditor>
                <!-- Path to script folder - no ending "/" -->
                <scriptFolderPath>/scripts</scriptFolderPath>
                <!-- what files can be opened/created in the script editor -->
                <scriptFileTypes>js,xml</scriptFileTypes>
                <!-- disable the codepress editor and use a simple textarea instead -->
                <!-- note! codepress editor always disabled in IE due to automatic hyperlinking "feature" in contenteditable areas -->
                <scriptDisableEditor>false</scriptDisableEditor>
            </scripteditor>
    
            <!-- should umbraco store the uploaded files like /media/xxx/filename.ext or like /media/xxx-filename.ext
            should be set to false if the aspnet account hasn't got readrights of the driveroot up to the /media directory -->
            <UploadAllowDirectories>True</UploadAllowDirectories>
            <errors>
                <!-- the id of the page that should be shown if the page is not found -->
                <!--        <errorPage culture="default">1</errorPage>-->
                <!--        <errorPage culture="en-US">200</errorPage>-->
                <error404>1</error404>
            </errors>
            <notifications>
                <!-- the email that should be used as from mail when umbraco sends a notification -->
                <email>[email protected]</email>
            </notifications>
    
            <!-- if true umbraco will ensure that no page under the same parent has an identical name -->
            <ensureUniqueNaming>True</ensureUniqueNaming>
    
            <!-- lowercase, either 'gif' or 'png' -->
            <graphicHeadlineFormat>gif</graphicHeadlineFormat>
    
            <!-- clean editor content with use of tidy -->
            <TidyEditorContent>True</TidyEditorContent>
    
            <!-- the encoding type for tidy. Default is UTF8, options are ASCII, Raw, Latin1, UTF8, ISO2022, MacroMan-->
            <TidyCharEncoding>UTF8</TidyCharEncoding>
    
            <!-- to enable new content schema, this needs to be false -->
            <UseLegacyXmlSchema>false</UseLegacyXmlSchema>
    
            <!-- Whether to force safe aliases (no spaces, no special characters) at businesslogic level on contenttypes and propertytypes -->
            <!-- HIGHLY recommend to keep this to true to ensure valid and beautiful XML Schemas -->
            <ForceSafeAliases>true</ForceSafeAliases>
    
            <!-- Enable / disable xml content cache -->
            <XmlCacheEnabled>True</XmlCacheEnabled>
    
            <!-- Update disk cache every time content has changed -->
            <ContinouslyUpdateXmlDiskCache>True</ContinouslyUpdateXmlDiskCache>
    
            <!-- Show the /config/splashes/booting.aspx page while initializing content -->
            <EnableSplashWhileLoading>False</EnableSplashWhileLoading>
    
            <!-- Show property descriptions in editing view "icon|text|none" -->
            <PropertyContextHelpOption>text</PropertyContextHelpOption>
    
            <!-- The html injected into a (x)html page if Umbraco is running in preview mode -->
            <PreviewBadge><![CDATA[<a id="umbracoPreviewBadge" style="position: absolute; top: 0; right: 0; border: 0; width: 149px; height: 149px; background: url('{1}/preview/previewModeBadge.png') no-repeat;" href="{0}/endPreview.aspx?redir={2}"><span style="display:none;">In Preview Mode - click to end</span></a>]]></PreviewBadge>
    
            <!-- Cache cycle of Media and Member data fetched from the umbraco.library methods -->
            <!-- In seconds. 0 will disable cache -->
            <UmbracoLibraryCacheDuration>1800</UmbracoLibraryCacheDuration>
        </content>
    
        <requestHandler>
            <!-- this will ensure that urls are unique when running with multiple root nodes -->
            <useDomainPrefixes>false</useDomainPrefixes>
            <!-- this will add a trailing slash (/) to urls when in directory url mode -->
            <addTrailingSlash>true</addTrailingSlash>
            <urlReplacing removeDoubleDashes="true">
                <char org=" ">-</char>
                <char org="&quot;"></char>
                <char org="%"></char>
                <char org="."></char>
                <char org=";"></char>
                <char org="/"></char>
                <char org=":"></char>
                <char org="#"></char>
                <char org="+">plus</char>
                <char org="*">star</char>
                <char org="&amp;"></char>
                <char org="?"></char>
                <char org="æ">ae</char>
                <char org="ø">oe</char>
                <char org="å">aa</char>
                <char org="ä">ae</char>
                <char org="ö">oe</char>
                <char org="ü">ue</char>
                <char org="ß">ss</char>
                <char org="Ä">ae</char>
                <char org="Ö">oe</char>
            </urlReplacing>
        </requestHandler>
    
        <templates>
            <useAspNetMasterPages>true</useAspNetMasterPages>
        </templates>
    
    
        <!-- this is used by Umbraco to determine if there's valid classes in the /App_Code folder to be used for Rest/XSLT extensions -->
        <developer>
            <appCodeFileExtensions>
                <ext>cs</ext>
                <ext>vb</ext>
            </appCodeFileExtensions>
        </developer>
    
        <scripting>
            <razor>
                <!-- razor DynamicNode typecasting detects XML and returns DynamicXml - Root elements that won't convert to DynamicXml -->
                <notDynamicXmlDocumentElements>
                    <element>p</element>
                    <element>div</element>
                </notDynamicXmlDocumentElements>
            </razor>
        </scripting>
    
        <!-- This moves the asp.net viewstate data to the end of the html document instead of having it in the beginning-->
        <viewstateMoverModule enable="false" />
    
        <logging>
            <enableLogging>true</enableLogging>
            <enableAsyncLogging>true</enableAsyncLogging>
            <disabledLogTypes>
                <!-- <logTypeAlias>[alias-of-log-type-in-lowercase]</logTypeAlias> -->
            </disabledLogTypes>
            <!-- You can add your own logging tool by implementing the umbraco.BusinessLogic.Interfaces.ILog interface and add the reference here -->
            <!-- The external logger can also act as the audit trail storage by setting the logAuditTrail attribute to true -->
            <!--<externalLogger assembly="~/bin/assemblyFileName.dll" type="fully.qualified.namespace.and.type" logAuditTrail="false" /> -->
        </logging>
    
        <scheduledTasks>
            <!-- add tasks that should be called with an interval (seconds) -->
            <task log="true" alias="YouTubeImport" interval="600" url="/umbraco/ImportVideos.aspx"/>
        </scheduledTasks>
    
        <!-- distributed calls make umbraco use webservices to handle cache refreshing -->
        <distributedCall enable="false">
            <!-- the id of the user who's making the calls -->
            <!-- needed for security, umbraco will automatically look up correct login and passwords -->
            <user>0</user>
            <servers>
                <!-- add ip number or hostname, make sure that it can be reached from all servers -->
                <!-- <server>127.0.0.1</server>-->
            </servers>
        </distributedCall>
    
        <!-- configuration for webservices -->
        <!-- webservices are disabled by default. Set enable="True" to enable them -->
        <webservices enabled="False">
            <!-- You must set user-rights for each service. Enter the usernames seperated with comma (,) -->
            <documentServiceUsers>your-username</documentServiceUsers>
            <fileServiceUsers>your-username</fileServiceUsers>
            <stylesheetServiceUsers>your-username</stylesheetServiceUsers>
            <memberServiceUsers>your-username</memberServiceUsers>
            <templateServiceUsers>your-username</templateServiceUsers>
            <!-- type of files (extensions) that are allowed for the file service -->
            <fileServiceFolders>css,xslt</fileServiceFolders>
        </webservices>
    
        <!-- Configuration for repositories -->
        <!-- Add or remove repositories here. You will need the repository's unique key to be able to connect to it.-->
        <repositories>
            <repository name="Umbraco package Repository" guid="65194810-1f85-11dd-bd0b-0800200c9a66" />
        </repositories>
    
        <providers>
            <users>
                <!-- if you wish to use your own membershipprovider for authenticating to the umbraco back office -->
                <!-- specify it here (remember to add it to the web.config as well) -->
                <DefaultBackofficeProvider>UsersMembershipProvider</DefaultBackofficeProvider>
            </users>
        </providers>
    
        <!-- Maps language, usertype, application and application_url to help pages -->
        <help defaultUrl="http://our.umbraco.org/wiki/umbraco-help/{0}/{1}">
            <!-- Add links that should open custom help pages -->
            <!--<link application="content" applicationUrl="dashboard.aspx"  language="en" userType="Administrators" helpUrl="http://www.xyz.no?{0}/{1}/{2}/{3}" /> -->
        </help>
    
    </settings>
    
    It's pretty much a stock config asside from the task I set up.
        <!-- Add links that should open custom help pages -->
        <!--
    

    -->

  • Jason N 55 posts 79 karma points
    Jun 07, 2011 @ 18:33
    Jason N
    0

    I also noticed that when I try to access the tags directly on the Document such as Model.tags, they don't seem to be there.  @Model.tags.Length outputs zero.  I can't get the tags unless I use umbraco.cms.businesslogic.Tags.Tag.GetTags(Model.Id), which would be very unpractical for filtering.   Surely there's an easy way to filter by tags with Razor?

  • Jason N 55 posts 79 karma points
    Jun 07, 2011 @ 21:07
    Jason N
    1

    Not exactly what I wanted but a helper method like the following seems to do the trick.

            public static DynamicNodeList SearchByTag(string tag)
            {
                var docs = Tag.GetDocumentsWithTags(tag);
                return new DynamicNodeList(docs.Select(doc => new DynamicNode(doc.Id)));
            }
Please Sign in or register to post replies

Write your reply to:

Draft