Coder Social home page Coder Social logo

Comments (7)

LiaraAlis avatar LiaraAlis commented on August 29, 2024 2

@blockberd Currently I use this template in our theme:

{extends file='parent:widgets/swag_digital_publishing/components/cover.tpl'}

{block name='widgets_digital_publishing_components_cover'}
    {if $media.attributes.webp}
        {$data = "{$media.attributes.webp.image} base"}
    {else}
        {$data = "{$media.source} base"}
    {/if}

    {if $media.thumbnails}
        {foreach $media.thumbnails as $image}
            {if $image.webp}
                {$data = "{$data}, {$image.webp.source} {$image.webp.maxWidth}"}
            {else}
                {$data = "{$data}, {$image.source} {$image.maxWidth}"}
            {/if}

            {if $image.webp.retinaSource}
                {$data = "{$data}, {$image.webp.retinaSource} {$image.webp.maxWidth} 2x"}
            {elseif $image.retinaSource}
                {$data = "{$data}, {$image.retinaSource} {$image.maxWidth} 2x"}
            {/if}
        {/foreach}
    {/if}

    <div class="cover"
         data-cover="true"
         data-srcSet="{$data}"
         {if $position}data-position="{$position}"{/if}>
    </div>
{/block}

from froshwebp.

shyim avatar shyim commented on August 29, 2024

I guess the replacement does not happen on the <source element. How looks the rendered html?

from froshwebp.

digitalpuls avatar digitalpuls commented on August 29, 2024

Thanks for the quick reply!
You mean like in the picture:

image

Am I placing it correctly?

from froshwebp.

LiaraAlis avatar LiaraAlis commented on August 29, 2024

@digitalpuls You can use this template. Tested in our theme and working.

{extends file='parent:widgets/swag_digital_publishing/components/image.tpl'}

{block name='widgets_digital_publishing_components_image_element'}
    {$style = "padding: {$element.paddingTop / 16}rem {$element.paddingRight / 16}rem {$element.paddingBottom / 16}rem {$element.paddingLeft / 16}rem;"}
    {$style = "{$style} text-align: {$element.orientation};"}

    {$wrapperStyle = "max-width: {$element.maxWidth / 16}rem;"}
    {$imageStyle = "max-height: {$element.maxHeight / 16}rem;"}

    {$src = $element.media.source}

    {if $element.media.thumbnails}
        {foreach $element.media.thumbnails as $thumbnail}
            {if $thumbnail.maxWidth >= $element.maxWidth}
                {$src = $thumbnail.sourceSet}
                {break}
            {/if}
        {/foreach}
    {/if}
    <div class="dig-pub--image" style="{$style}">
        <div class="dig-pub--img-wrapper" style="{$wrapperStyle}">
            <picture>
                {if $thumbnail.webp}
                    <source srcset="{$thumbnail.webp.sourceSet}" type="image/webp">
                {/if}
                <img srcset="{$src}"
                     class="dig-pub--img{if $element.class} {$element.class}{/if}"
                     style="{$imageStyle}"
                        {if $element.alt} alt="{$element.alt}"{/if} />
            </picture>
        </div>
    </div>
{/block}

Now I'm also searching for a solution for the cover.tpl template. :D

@shyim Can we add this to the plugin?

from froshwebp.

shyim avatar shyim commented on August 29, 2024

Can you make here too an PR? :)

from froshwebp.

LiaraAlis avatar LiaraAlis commented on August 29, 2024

@shyim Also done.

from froshwebp.

blockberd avatar blockberd commented on August 29, 2024

Now I'm also searching for a solution for the cover.tpl template. :D

Hello, where you able to find a solution for the cover.tpl? I'm currently stuck on that part and not able to find a way to implement it. I think my issue might be from the fact that the WebP files are only generated for the thumbnails but the images used in cover.tpl do not follow the same thumbnail structure / are no real thumbnails.

Any ideas?

from froshwebp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.