I want to create a breadcrumb and want to populate my view based on some condition. So, I want to have a if clause after each iteration. I need help.

  • 1
    Hi Saurav, Welcome to SSE we are glad you found this site. While we would love to help you with your question, we would need more information from you, things like code examples, what you have tried, what your setup is etc... Please take a look at these guidelines on What Makes a Good Post. – Richard Seal Oct 8 at 12:19

I hope this might help, since you have not given any detailed explanation.

 @foreach (eachbreadcrumblink){
                <li>
                    <a href="">BreadcrumbLink   </a>
                </li>
}

If you explain the scenario in detail, we can help more also provide some details what you have tried to implement, even it is too small.

  • The scenario is I want to create a breadcrumb and I am fetching data from GraphQl search query and then I am going to iterate the same as showing below. – Saurav Oct 10 at 5:41
  • The scenario is I want to create a breadcrumb and I am fetching data from GraphQl search query and then I am going to iterate the same. I want to add some condition like if showMenu checkbox is checked and and if the item has any parent and that parent is not home then I will the method again. I am not able to add proper code syntax for the same. I need help. – Saurav Oct 10 at 6:12

Totally guessing here that you're using JSS with React, in which case JSX is a bit different from your average conditional statement.

Given something like this:

const input = [{ name: 'nav1', show: true}, { name: 'nav2', show: false }];

You can loop over it in JSX something like:

const ReactComponent = ({ input }) => <div>
      {input.map((item, index) => {item.show && <div key={index}>{item.name}</div>})}
   </div>;

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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