def siblings_along_path_to(page_list, page2):
    """
    Filters a list of pages so that only those remain that are either:

        * An ancestor of the current page
        * A sibling of an ancestor of the current page

    A typical use case is building a navigation menu with the active
    path to the current page expanded::

        {% feincms_nav feincms_page level=1 depth=3 as navitems %}
        {% with navitems|siblings_along_path_to:feincms_page as navtree %}
            ... whatever ...
        {% endwith %}

    """

    if page_list:
        try:
            # Try to avoid hitting the database: If the current page is
            # in_navigation, then all relevant pages are already in the
            # incoming list, no need to fetch ancestors or children.

            # NOTE: This assumes that the input list actually is complete (ie.
            # comes from feincms_nav). We'll cope with the fall-out of that
            # assumption when it happens...
            ancestors = [
                a_page
                for a_page in page_list
                if a_page.is_ancestor_of(page2, include_self=True)
            ]
            top_level = min(a_page.level for a_page in page_list)

            if not ancestors:
                # Happens when we sit on a page outside the navigation tree so
                # fake an active root page to avoid a get_ancestors() db call
                # which would only give us a non-navigation root page anyway.
                page_class = _get_page_model()

                p = page_class(
                    title="dummy", tree_id=-1, parent_id=None, in_navigation=False
                )
                ancestors = (p,)

            siblings = [
                a_page
                for a_page in page_list
                if (
                    a_page.parent_id == page2.id
                    or a_page.level == top_level
                    or any(_is_sibling_of(a_page, a) for a in ancestors)
                )
            ]

            return siblings
        except (AttributeError, ValueError) as e:
            logger.warn(
                "siblings_along_path_to caught exception: %s", format_exception(e)
            )

    return ()

    Filters a list of pages so that only those remain that are either:

        * An ancestor of the current page
        * A sibling of an ancestor of the current page

    A typical use case is building a navigation menu with the active
    path to the current page expanded::

        {% feincms_nav feincms_page level=1 depth=3 as navitems %}
        {% with navitems|siblings_along_path_to:feincms_page as navtree %}
            ... whatever ...
        {% endwith %}

    
feincms/templatetags/feincms_page_tags.py