Copied to clipboard

Flag this post as spam?

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


  • Patrick 2 posts 22 karma points
    Dec 07, 2012 @ 15:00
    Patrick
    0

    Categorisation Package for Umbraco - How to list categories and assigned documents

    Is there a tutorial out there that might help me display the categories that I’ve created and assigned to my docs? Razor would be preferable if possible. Basically, I’m trying to have something like:

    Boats (Link to list page of Boat Articles)
    - Recent Document 1 about Boats (Link to Doc)
    - Recent Document 2 about Boats (Link to Doc)
    - Recent Document 3 about Boats (Link to Doc)

    Cars (Link to list page of Cars Articles)
    - Recent Document 1 about Cars (Link to Doc)
    - Recent Document 2 about Cars (Link to Doc)
    - Recent Document 3 about Cars (Link to Doc)

    I’ve having the toughest time organizing by categories.

  • James Patterson 53 posts 192 karma points
    Dec 09, 2012 @ 13:51
    James Patterson
    0

    Hi Patrick,

    Below is a bit of code that should help. It assumes the following things;

    • Category pages are children of the current page.
    • Category pages have a property with alias 'category' which contains the ID of the category the page is associated with (in your example it would list pages in that category).
    • Categories which are assigned to nodes are in the property with alias 'categories'.
    @inherits umbraco.MacroEngines.DynamicNodeContext

    @using Auros.Categorisation

    <ul>
    @foreach (var childNode in Model.Children) 
    {
        if (childNode.HasProperty("category"))
        {
            <li>
                <a href="@childNode.Url">@childNode.Name</a>
                <ul>
                    @foreach (var nodeInCategory in NodeHelpers.GetNodesInCategory("categories", Categories.GetCategory((int)childNode.Category)).OrderByDescending(n => n.CreateDate).Take(3))
                    {
                        <li><a href="@nodeInCategory.NiceUrl">@nodeInCategory.Name</a></li>
                    }
                </ul>
            </li>
        }
    }
    </ul>

    The above code will list category pages and the latest three pages which have that category assigned.

    At the moment there is no single category selection data type, so the ID would have to be entered manually on the category page, but I've noted this for future releases of the categorisation package.

    If you have any questions, let me know.

    Cheers,
    James

  • James Patterson 53 posts 192 karma points
    Dec 12, 2012 @ 18:17
    James Patterson
    0

    Hi Patrick,

    I uploaded a new version of the Categorisation package today - version 2.2.0.0. There is now a single category data type named Category Picker and a new static method in the Categories class named FindCategoryByName which should be helpful to you.

    Thanks,
    James

  • mark petty 20 posts 40 karma points
    Mar 21, 2013 @ 10:39
    mark petty
    0

    Hi

    Does anyone know how I can do the following?

    1. List all the categories on a page as links
    2. When a user clicks on a category it then filters for all the pages that has the category assigned.

    Any help much appreciated

    Mark

  • James Patterson 53 posts 192 karma points
    Mar 21, 2013 @ 23:01
    James Patterson
    0

    Hi Mark,

    Have you had a look at the documentation?: https://umbracocategories.codeplex.com/documentation

    There's a couple of ways to do this, it depends on the technique you want to use. It would be straight-forward to create a user control listing all categories using Categories.GetCategories(), which returns an array of all active categories, then output a link for each category using the current page URL and appending each category ID as a query string parameter. Then you can query Umbraco for nodes/pages with the selected category by using NodeHelpers.GetNodesInCategory().

    If you want to use XSLT then there are extensions like GetCategories() for getting all active categories and listing them.

    If you need some code samples then this is something that can be added to the samples project (http://our.umbraco.org/FileDownload?id=4755)

    Thanks,
    James 

     

     

     

  • mark petty 20 posts 40 karma points
    Mar 22, 2013 @ 10:09
    mark petty
    0

    Cheers James, I managed to do this in the end.

    I did what you said and created an XSLT that lists all the categories. I appended the id in to the querystring.
    I then created a user control that filters the results depending on the value from the querystring.

    Seems to work really well.

    Thanks

    Mark

     

  • James Patterson 53 posts 192 karma points
    Mar 22, 2013 @ 22:53
    James Patterson
    0

    Excellent. Glad you got it working!

    Cheers

  • Peter 6 posts 26 karma points
    Apr 02, 2013 @ 10:25
    Peter
    0

    Hello,

    Could you please help?

    I want to display the categories added to the blog. I used a macro to xsl (from example). I can't display it. Could you please help me... I need to change something in the code?

    I have categories:

    1) main news
    - news type A
    - news type B

    -

    Cheers
    Peter



    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
        <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:Auros.Categories="urn:Auros.Categories"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Auros.Categories ">


        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <xsl:param name="currentPage"/>

        <xsl:template match="/">

            <xsl:variable name="categoryXml" select="Auros.Categories:GetCategoriesFromCSV($currentPage/categories)" />

            <xsl:if test="count($categoryXml//category) &gt; 0">
                <ul>
                    <xsl:for-each select="$categoryXml//category">
                        <li>
                            <xsl:value-of select="./name" />
                        </li>
                    </xsl:for-each>
                </ul>
            </xsl:if>

        </xsl:template>

    </xsl:stylesheet>

  • James Patterson 53 posts 192 karma points
    Apr 03, 2013 @ 09:57
    James Patterson
    0

    Hi Peter,

    I'll have to test this out later, but I'm not seeing anything wrong right now.

    Try a couple of things to troubleshoot this;

    1. Make sure the property alias for the categories on the document type is actually 'categories'.
    2. Make sure categories have actually saved against the page you're using to test the XSLT script.

    If all seems fine;

    • What is the value of $currentPage/categories?
    • Try outputting the returned XML from the GetCategoriesFromCSV extension.

    Thanks,
    James

  • mark petty 20 posts 40 karma points
    Apr 09, 2013 @ 13:39
    mark petty
    0

    Hi James

    Do you know if it is possible to get the id of the categories using GetCategories()?

    Thanks

    Mark

     

  • James Patterson 53 posts 192 karma points
    Apr 12, 2013 @ 22:42
    James Patterson
    0

    Hi Mark,

    Sorry for the late reply, I've been in Belgium all week (without a laptop!) and commenting on threads doesn't work on an iPhone for some reason.

    I had a look and was suprised to see I'd left it out - this is a mistake and will be corrected. I should have some time on Sunday so hopefully I'll get a small update out then.

    Cheers,
    James 

  • James Patterson 53 posts 192 karma points
    Apr 14, 2013 @ 14:31
    James Patterson
    0

    Hi Mark,

    The ID should now be returned by all the XSLT extensions which return categories as XML, see the 'id' attribute.

    Check out the beta release of the package here: https://umbracocategories.codeplex.com/releases/view/105052

    Thanks,
    James

  • mark petty 20 posts 40 karma points
    Apr 15, 2013 @ 11:21
    mark petty
    0

    Thank you very much James

  • mark petty 20 posts 40 karma points
    Apr 15, 2013 @ 12:21
    mark petty
    0

    Hi James

    i uninstalled the version I had and reinstalled the new update. Now I seem to be getting the following error everytime I go in to the content:

    Server Error in '/' Application.


    Value cannot be null.
    Parameter name: name

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentNullException: Value cannot be null.
    Parameter name: name

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [ArgumentNullException: Value cannot be null.
    Parameter name: name]
       System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) +9554485
       umbraco.cms.businesslogic.datatype.BaseDataType.LoadSettings(List`1 settings) +187
       umbraco.cms.businesslogic.datatype.AbstractDataEditorControl.OnInit(EventArgs e) +94
       System.Web.UI.Control.InitRecursive(Control namingContainer) +140
       System.Web.UI.Control.InitRecursive(Control namingContainer) +311
       System.Web.UI.Control.InitRecursive(Control namingContainer) +311
       System.Web.UI.Control.InitRecursive(Control namingContainer) +311
       System.Web.UI.Control.InitRecursive(Control namingContainer) +311
       System.Web.UI.Control.AddedControl(Control control, Int32 index) +197
       System.Web.UI.ControlCollection.Add(Control child) +79
       umbraco.controls.ContentControl.AddControlNew(Property p, TabPage tp, String Caption) +3738
       umbraco.controls.ContentControl.LoadPropertyTypes(IContentTypeComposition contentType, TabPage tabPage, Hashtable inTab, Int32 tabId, String tabCaption) +257
       umbraco.controls.ContentControl.CreateChildControls() +603
       System.Web.UI.Control.EnsureChildControls() +102
       umbraco.controls.ContentControl.OnInit(EventArgs e) +38
       System.Web.UI.Control.InitRecursive(Control namingContainer) +140
       System.Web.UI.Control.AddedControl(Control control, Int32 index) +197
       System.Web.UI.ControlCollection.Add(Control child) +79
       umbraco.cms.presentation.editContent.OnInit(EventArgs e) +1497
       System.Web.UI.Control.InitRecursive(Control namingContainer) +140
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +480
    

    I have tried to uninstall and reinstall an old version but I seem to get the same error. Any idea?

    Thanks

    Mark

     

  • James Patterson 53 posts 192 karma points
    Apr 15, 2013 @ 13:31
    James Patterson
    0

    Hi Mark,

    Are you using Umbraco 6.0.3? If so, I know there's a problem with this version as I saw the same thing yesterday. I haven't had a chance to find out what the problem is though. From my quick scout around on the forum yesterday it didn't seem like it was specific to my package.

    Hopefully I'll have a chance to look at this soon.

    Thanks,
    James

  • mark petty 20 posts 40 karma points
    Apr 15, 2013 @ 14:09
    mark petty
    0

    Hi James

    Yes i'm using 6.03.

    Thanks for your help

    Mark

  • mark petty 20 posts 40 karma points
    Apr 15, 2013 @ 14:34
    mark petty
    0

    Hi James

    It is very strange. As a test I create a new umbraco site without the categorisation package and the content loaded fine. I then added the older version of the categorisation (2.2.1.0) and I get the same error as above when trying to load the content.

    If I remove the categories property it loads ok but without the category selection :(

    Cheers

    Mark

     

  • mark petty 20 posts 40 karma points
    Apr 15, 2013 @ 14:47
    mark petty
    0

    Another strange thing I have noticed is that if I try and create a new data type I have no option to create a new CategoryTree (property editor). Only category picker is available.

    Do you think its liknked to this? http://our.umbraco.org/projects/backoffice-extensions/google-maps-datatype/bug-reports/39674-Value-cannot-be-null?p=0#comment146608

    I have tried re saving the default values but it doesn't work :(

  • James Patterson 53 posts 192 karma points
    Apr 15, 2013 @ 19:49
    James Patterson
    0

    Hi Mark,

    I know this is a problem occuring with other packages too, I think something has changed in Umbraco 6.0.3 to cause this.

    I do think it's related to that link but, like you say, the solution in that case doesn't work here for some reason - it was something I tried yesterday afternoon.

    Thanks for the information, I'll look into this issue as soon as I can.

    Thanks,
    James 

  • mark petty 20 posts 40 karma points
    Apr 16, 2013 @ 10:06
    mark petty
    0

    No worries James.

    I spent all day yesterday looking at this and have finally found a work around. The issue is related to the DataType, if you create a new DataType with the Category Tree as the property editor and save it (also re assign the property within the document type). This will fix the issue.

    It is a massive pain though and hopefully Umbraco can sort this out in a new release.

    Where do you reckon I should log this as an issue? i'm still new to Umbraco so not quite sure the best forum to log this on?

    Thanks,

    Mark

     

     

  • mark petty 20 posts 40 karma points
    Apr 16, 2013 @ 10:18
  • Richard Barg 358 posts 532 karma points
    Jun 12, 2013 @ 22:02
    Richard Barg
    0

    James, 

    Please take a look at this. We tested this and it works great with the content and media trees. It's based on JS on the client side.

    http://pynej.blogspot.com/2013/05/enable-drag-and-drop-on-content-and.html

    Drag and drop would be an outstanding addition to the Categorisation tree if you do something similar, perhaps levereging this code to work.  The developer of this Jeremy Pyne has a Google+ page should you want to ask him about it. https://plus.google.com/u/0/s/umbraco%20pyne?cfem=1

     

  • James Patterson 53 posts 192 karma points
    Jun 12, 2013 @ 22:12
    James Patterson
    0

    Thanks a lot Richard! That's something I'll be looking at for sure.

Please Sign in or register to post replies

Write your reply to:

Draft