0

We have a site with Managed Metadata enabled. In that we have Term sets and 2 levels of Terms and every one has a unique page associated with it.

Building 1

    Floor 1

    Floor 2

        House 1

        House 2

        House 3

Building 2

    Floor 3

         House 4

         House 5

         House 6
    Floor 4
         House 7

Building 3

    Floor 5

         House 8
         House 9

Buildings - Level 1.

Floor - Level 2.

House - Level 3.

Now my requirement is : To show the name of Floors under it, if I am viewing any Building Page ; show the name of Houses under it, if I am viewing a floor page.

For Example, If I am viewing, Building 2, i should be able to see the links of floor pages for that building, (i.e) Floor 3 and Floor 4. If I am viewing Floor 5 page, I have to see the House 8 and House 9 links there.

I went for the approach of using Table of Contents webpart. I am able to statically fulfill the requirement by giving the Full url on the "start with location" text box, when i edit the webpart. Now i need to do it dynamically. (i.e) wherever this webpart is been placed, it should get the URL and pass it as a value to the"start with location" parameter.

First I tried with Page Layouts approach, I added this webpart using snippet gallery, and tried to customize it. Inside the page layout, I have to pass the page's url to the "AnchorLocation" parameter of the webpart.

Generally , Through javascript I can get the url of the page. But I am not able to do inside page layouts. My javascript function was not called, also i was not aware of the format(syntax)to pass value to the "AnchorLocation".

Then i tried exporting the webpart. I did that and I opened the .webpart file in visual studio. Here also I have to give value to the "AnchorLocation". I am not sure how to call my javascript and to pass value to the "AnchorLocation".

Any help would be much appreciated, Please let me know, if my explanation is not clear.

1 Answer 1

0

Another approach with javascript (multilingual):

1st: Insert a TOC example div on the page content (via Content Editor WP)

<!-- Table of Contents -->
    <div id="wiki-index">
        <div id="ToC" class="toc">Table of Contents</div> 
    </div>
<!-- Table of Contents -->

2nd: Inject the following js code via Script Editor web part. (or other way)

<script type="text/javascript">
            var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;

            if (inDesignMode == "1")
            {
               // page is in edit mode
            }
            else
            {
                $(document).ready(function () {
                    $("h1, h2, h3").each(function (i) {
                        var current = $(this);
                        current.attr("id", $(this).text() + i);
                        var pos = current.position().top / $("#content").height() * $(window).height();
                        $("#wiki-index").append("<a id='link" + i + "' href='#" + $(this).text() + i + "' title='" + $(this).text() + "'>" + current.html() + "</a><br/>");
                        $("#link" + i).css("top", pos);
                    });
                    if (L_Menu_LCID == 1031) document.getElementById("ToC").innerText = "Inhaltsverzeichnis";
                    if (L_Menu_LCID == 1033) document.getElementById("ToC").innerText = "Table of Contents";
                    if (L_Menu_LCID == 1036) document.getElementById("ToC").innerText = "Table des matières";
                    if (L_Menu_LCID == 1040) document.getElementById("ToC").innerText = "Elenco";
                });
            }

</script> 

Info: the above code will pick from the whole page content any css class defined on the js code and create the TOC elements.

3
  • I tried your script. But this is not I expect for my current requirement. But thanks for the answer. I need to know how to pass value to the "AnchorLocation" in the webpart xml
    – CHANDRU D
    Commented Jun 10, 2016 at 9:10
  • I know, was just to give you another possible workaround. Good luck with that, :)
    – fallout
    Commented Jun 10, 2016 at 9:45
  • Guys, I have got the solution. I have implemented and it worked perfectly. Check this link.. social.msdn.microsoft.com/Forums/office/en-US/…
    – CHANDRU D
    Commented Jun 10, 2016 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.