V6 dynamic sheet modal, how to pass data to the sheet content dynamically created in v6?

Checking the sample online and knowing template7 is not more in v6 how will you pass data to content in a dynamic sheet in v6?

here a dynamic sheet modal

// Create sheet modal
      if (!sheet) {
        sheet = $f7.sheet.create({
          content: '\
            <div class="sheet-modal">\
              <div class="toolbar">\
                <div class="toolbar-inner justify-content-flex-end">\
                  <a href="#" class="link sheet-close">Close</a>\
                </div>\
              </div>\
              <div class="sheet-modal-inner">\
                <div class="page-content">\
                  <div class="block">\
                    <p>This sheet modal was created dynamically</p>\
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse faucibus mauris leo, eu bibendum neque congue non. Ut leo mauris, eleifend eu commodo a, egestas ac urna. Maecenas in lacus faucibus, viverra ipsum pulvinar, molestie arcu. Etiam lacinia venenatis dignissim. Suspendisse non nisl semper tellus malesuada suscipit eu et eros. Nulla eu enim quis quam elementum vulputate. Mauris ornare consequat nunc viverra pellentesque. Aenean semper eu massa sit amet aliquam. Integer et neque sed libero mollis elementum at vitae ligula. Vestibulum pharetra sed libero sed porttitor. Suspendisse a faucibus lectus.</p>\
                  </div>\
                </div>\
              </div>\
            </div>\
          ',
          on: {...

In v5 I was using template7 but in v6
what should I change? I need to pass data to the content as before…

I tried like this it is not working for me…

     sheet = $f7.sheet.create({
     content: $h`
        <div class="page">
          <div class="navbar">
            <div class="navbar-bg"></div>
            <div class="navbar-inner">
              <div class="title">${title}</div>
            </div>
          </div>
          <div class="page-content">
            <a @click=${openAlert} class="red-link">Open Alert</a>
            <div class="list simple-list">
              <ul>
                ${names.map((name) => $h`
                  <li>${name}</li>
                `)}
              </ul>
            </div>
          </div>
        </div>
      `,
...

I also tried this as an action inside store.js, and it prints out the array but incorrectly taking the comma ‘,’ as an array element too…

    openSheet({
      state
    }, {
      $f7, $
    }, ) {

      const title = 'This sheet modal was created dynamically';
      const names = ['John', 'Vladimir', 'Timo'];

        var sheet = $f7.sheet.create({
          content: `
            <div class="sheet-modal">
              <div class="toolbar">
                <div class="toolbar-inner justify-content-flex-end">
                  <a href="#" class="link sheet-close">Close</a>
                </div>
              </div>
              <div class="sheet-modal-inner">
                <div class="page-content">
                  <div class="block">
                    <p>${title}</p>
                    ${names.map((name) => `
                      <p>${name}</p>
                    `)}
                  </div>
                </div>
              </div>
            </div>
          `,
          on: {
            open: function (sheet) {
              console.log('sheet opening...');
            },
            opened: function (sheet) {
              console.log('sheet opened...');
            },
            close: function (sheet) {
              console.log('sheet closing...');
            },
            closed: function (sheet) {
              console.log('sheet closed...');
              sheet.destroy();
            },
          },

        });

        sheet.open();

    },

output error taking also the comma as an array element to print:

John
,
Vladimir
,
Timo
,

here the image showing the problem:

Screenshot 2021-02-26 at 12.25.19

I also tried this way

    openSheet({
      state
    }, {
      $f7, $, $h
    }, ) {

      const title = 'This sheet modal was created dynamically';
      const names = ['John', 'Vladimir', 'Timo'];

      var tmp = $h`
      <div class="sheet-modal">
        <div class="toolbar">
          <div class="toolbar-inner justify-content-flex-end">
            <a href="#" class="link sheet-close">Close</a>
          </div>
        </div>
        <div class="sheet-modal-inner">
          <div class="page-content">
            <div class="block">
              <p>${title}</p>
              ${names.map((name) => $h`
                <p>${name}</p>
              `)}
            </div>
          </div>
        </div>
      </div>
      `;

        console.log(tmp);

        var sheet = $f7.sheet.create({
          content: tmp,
          on: {
            open: function (sheet) {
              console.log('sheet opening...');
            },
            opened: function (sheet) {
              console.log('sheet opened...');
            },
            close: function (sheet) {
              console.log('sheet closing...');
            },
            closed: function (sheet) {
              console.log('sheet closed...');
              sheet.destroy();
            },
          },

        });

        sheet.open();

    },

but I get this error in the console:

Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'modal.params.animate')

printing the tmp variable to the console seems OK

 console.log(tmp);

See image

I did not find any sample for dynamic modal sheet in v6 with dynamic content feed in the documentation…

Am I missing something or is not the correct way? maybe a good sample for modal sheet with dynamic content will help!

Any tip or help appreciated!

This is JS basics, ES template literals: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

And how do you transform array to a string in JS? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join

          content: `
            <div class="sheet-modal">
              <div class="toolbar">
                <div class="toolbar-inner justify-content-flex-end">
                  <a href="#" class="link sheet-close">Close</a>
                </div>
              </div>
              <div class="sheet-modal-inner">
                <div class="page-content">
                  <div class="block">
                    <p>${title}</p>
                    ${names.map((name) => `
                      <p>${name}</p>
                    `).join('')}
                  </div>
                </div>
              </div>
            </div>
          `,
1 Like

Thank you for your reply regarding this, I thought about using .join(’’) as I used .trim() at the end but I was not sure if this was the correct approach to take in framework7 v6 not seeing any documentation or samples specified for v6 regarding this topic of how to deal with dynamic content in dynamic modal sheets when migrating from v5 with template7.

Now I know I was close to the approach but I didn’t know if I was correct and I didn’t want to cause some issues in f7 v6 somewhere if this was not the correct way to use it for this case!

Thank you to confirm this with this information, this helps!
A sample in the documentation will help that too!

Thanks!

There is no any magic here, if you use ES templates then just any rules for vanilla JS are valid here, same in component templates but with using $h

1 Like

Thanks for the tips! :slightly_smiling_face: :+1: