Hi, I'm trying to writing a basic FAQs page with questions and answers in separate blocks. When a Q is clicked it takes the reader down the page to the answer in another block.

I am code-ignorant but so far I see, using Views, I need to output the question as a link and use global counters as a locator.
In the upper and lower blocks I have a Global results counters.
In the lower block I have in the title field as a rewrite with text: a name="[counter]">[title]

Writing the link from the question field in the upper block is what is stumping me.

Comments

jaypan’s picture

Take a look at the FAQ module. It already does this for you.

Contact me to contract me for D7 -> D10/11 migrations.

davidjsn’s picture

Thanks for the reply.

I've tried these but I get 404 errors for the page examples and there are no same page block-to-block examples there.

jaypan’s picture

I mean the FAQ module already provides this entire page for you. It lists the FAQ questions at the top, and when you click them, it brings you further down the page to the answer. Or, you can set it up to open the answers on separate pages, or to even expand to show the answer under the question itself.

Contact me to contract me for D7 -> D10/11 migrations.

davidjsn’s picture

Apologies first if I don't get how it works but I've been over it so many times and not seen what I want in either settings or examples. I don't want an entire page, I want two blocks to insert into a page containing other content.

jaypan’s picture

How it works is using anchor tags and hashes.

For example, I create a page, and somewhere way down the page I add a link as follows:
<a name="my_anchor"></a>
Note that I've not provided this tag with an href, only with a name. And I didn't give it any content, so it's not visible.

Next, I can link to the location of that anchor from anywhere else on the page using the following:
<a href="#my_anchor">Jump</a>

Clicking on the 'Jump' link will bring the user to the first anchor tag I created.

That's the basic principle behind it.

Edit: Note that I can also link to this anchor from any other page by using the following:
<a href="/path/to/page#my_anchor</a>
This will bring the user to the page, and then on that page to the first anchor tag I created.

Contact me to contract me for D7 -> D10/11 migrations.

davidjsn’s picture

Jaypan thanks for this. Is there a way to write this into the Views link ("output the field as a link") and reference the global counter as the name?

jaypan’s picture

I'm sorry, I rarely use Views, so I cannot help you with this. Hopefully someone else can pipe up with a solution for you.

Contact me to contract me for D7 -> D10/11 migrations.

davidjsn’s picture

In the upper block: add a global results field, followed in the title field "Output the field as a link" with the link path: path-to-page#[counter]. In the lower block: add a global results counter above the tilte field again (both global results fields set to "excluded from display")and in the title field under "Rewrite the output of this field" [title]