Announcement

Collapse
No announcement yet.

Targetting immediate parent section

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Targetting immediate parent section

    How would I target the immediate parent section of a given section.

    Assuming my products are in their own sections (for single product per page layout purposes), how do I target the section that these individual product sections are in? They're not all at the same sectionlevel.

    I'm trying to generate a productlist of all the products at the same level as the currently selected one (its for a jquery carousel doodad). There are too many products (and sections) in the database to make an entireselectionlist one...

    any advice?

    #2
    Breadcrumb trail might hold some clues/ideas on that one, not sure if you can use that. If not you'd need to php into the database i'd imagine and extract all products where their parent sectionID was equal to XX, each section has its own unique sectionID. I use something similar for 'shop by brand' sections, where you create a shop by brand TLS, then have subsections in that for each brand and i can then extract a list of the subsections of the TLS where their section ID is equal to that i have set.

    I manually set the sectionID into the code myself as it's always a one off (i use it for a drop down jump list on brands). So i'd say a similar approach would work, but instead of a hard coded sectionID, you'd need to get that reading dynamically according to the section which you are in, that is where the variable in the breadcrumb trail might present a nice bit of help i.e get the sectionID of the parent section.

    Comment


      #3
      Here's some demo code that works in a Product layout and simply displays the parent name of the current Section. It works by collecting the SectionLevel and then loops through ParentSectionList looking for one level lower.
      Code:
      <actinic:block php="true">$productsectionlevel = <actinic:variable name="SectionLevel" selectable="false" />;</actinic:block>
      <actinic:block type="ParentSectionList">
      	<actinic:block php="true">
      		$parentsectionlevel = <actinic:variable name="SectionLevel" selectable="false" />;
      		if ( $parentsectionlevel == ($productsectionlevel - 1) )
      			{
      			echo '<actinic:variable name="SectionName" encoding="perl" selectable="false" />';
      			}
      	</actinic:block>
      </actinic:block>
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        thanks for your input guys.

        Lee, I looked into the breadcrumb trail following your suggestion but I got nowhere. Nice idea but no cigar I'm afraid.

        Norman, I'd nearly got to this myself, but I did something rather more convoluted involving finding the penultimate term in a PHP array. Your code is much neater, thanks.

        Comment


          #5
          Thanks, I think I've got it working as intended now - the code I used was:

          Code:
          <ul>
          
          <actinic:block php="true">
          	$productsectionlevel = <actinic:variable name="SectionLevel" selectable="false" />;
          	<actinic:block type="ParentSectionList">
          	$parentsectionlevel = <actinic:variable name="SectionLevel" selectable="false" />;
          		if ( $parentsectionlevel == ($productsectionlevel - 1) )
          			{
          			$parentsection = "<actinic:variable name="SectionName" encoding="perl" selectable="false" />";
          			}
          	</actinic:block>
          
          	<actinic:block type="EntireSectionList" >
          		$currsection= "<actinic:variable name="SectionName" encoding="perl" selectable="false" />";						
          		if ($parentsection == $currsection) {
          		<actinic:block type="ChildSectionList" >
          			<actinic:block type="ProductList" >
          			echo "<li><a href=\"<actinic:variable name="SectionPageName"/>\"><actinic:variable name="SectionPageName" />";
          			echo "<img src=\"<actinic:variable name="ProductImageFileName" />\" class=\"carouselcount\" />";
          			echo "</a></li>";
          			</actinic:block>
          		</actinic:block>		
          		}
          	</actinic:block>
          </actinic:block>
          
          </ul>

          Comment


            #6
            Minor tweaks needed.

            When you pass a textual variable to PHP it needs to be within single quotes (not double ones) for the encoding="perl" bit to work properly. You may not see errors straight away but will if some items contain the single quote character.

            Also you should add selectable="false" to variables used within PHP or your code will fail in Design Mode.

            E.g.
            Code:
            <ul>
            
            <actinic:block php="true">
            	$productsectionlevel = <actinic:variable name="SectionLevel" selectable="false" />;
            	<actinic:block type="ParentSectionList">
            	$parentsectionlevel = <actinic:variable name="SectionLevel" selectable="false" />;
            		if ( $parentsectionlevel == ($productsectionlevel - 1) )
            			{
            			$parentsection = '<actinic:variable name="SectionName" encoding="perl" selectable="false" />';
            			}
            	</actinic:block>
            
            	<actinic:block type="EntireSectionList" >
            		$currsection= '<actinic:variable name="SectionName" encoding="perl" selectable="false" />';						
            		if ($parentsection == $currsection) {
            		<actinic:block type="ChildSectionList" >
            			<actinic:block type="ProductList" >
            			echo "<li><a href=\"<actinic:variable name="SectionPageName" selectable="false" />\"><actinic:variable name="SectionPageName" selectable="false" />";
            			echo "<img src=\"<actinic:variable name="ProductImageFileName" selectable="false" />\" class=\"carouselcount\" />";
            			echo "</a></li>";
            			</actinic:block>
            		</actinic:block>		
            		}
            	</actinic:block>
            </actinic:block>
            
            </ul>
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #7
              Quick addendum here:

              The customer has numerous subcategories that have the same name, and as a result content from these foreign sections is polluting my results. I haven't come up with an adequately robust solution yet, but I thought I'd post this in case it saves anybody else debugging time.
              • widgets
                • square
                  • green*
                  • red
                  • blue
                • circle
                  • orange
                  • green*
                  • purple

              Comment


                #8
                Try using SectionID instead of SectionName as the ID is unique.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  Not found five minutes to sit down an dlook at this, but it's so simple when you think about it. Thanks very much Norman.

                  Comment


                    #10
                    PHP runs slow with many section site

                    Hi Norman,
                    the code you posted in post 6 above works very well for displaying sibling sections and so is perfect for our site where we have SPPs (for our fabric products) which are members of the same parent section (Collection). But when as we have many SPP sections it parses very slowly. Is there a way of speeding this up or preventing actinic from parsing the php until upload?

                    Comment


                      #11
                      The code that I posted in #3 is fine. It's your code that I corrected in #6 that's the problem.

                      I see you added a block that uses EntireSectionList. This is the culprit as you now will be iterating through the square of your Section count. I.e. if you have 1,000 Sections you'll be doing 1,000,000 iterations. No wonder it's slow.

                      You could us a Condition based on IsPreviewMode to omit code while Previewing but it will still take ages on uploading.

                      Or change that EntireSectionList to use ParentSetionList followed by SubSectionList (perhaps more than one SubSectionList to get the depth you require).

                      Or rewrite what you're doing for much greater effiiency. E.g. use PHP to store the entire section structure (just the bits you need) into a PHP array or object. And find a way where this is only run once when needed.

                      These solutions aren't trivial and way beyond the scope of what can be provided for free.
                      Norman - www.drillpine.biz
                      Edinburgh, U K / Bitez, Turkey

                      Comment

                      Working...
                      X