Recommended Posts

Could you show your code and module settings?

Share this post

Link to post
Share on other sites

It works perfectly well:

<div <?php echo $page->images->first()->bgset('hero'); ?>>Lorem ipsum</div>

Call to a member function srcset() on a non-object

<img <?php echo $page->featured_image->srcset('featured-image'); ?>>

What should I do?

Share this post

Link to post
Share on other sites

doesn't return a valid object! (It returns a "non-object")
You need to check that it returns a valid image object. Check if you set the image field to return a single image or an array of images.
Also you always need a fallback for cases where no image is uploaded to a field!

  • Like 1

Share this post

Link to post
Share on other sites

Thank you! It works like this:

<img <?php echo $page->images->first()->srcset('featured-image'); ?>>


  • Like 1

Share this post

Link to post
Share on other sites

Just updated the module to version 0.1. Almost everything in it has changed so reading the docs is a must :)

The module does less "magic" as before, eg. doesn't add the "lazyload" class and data-sizes automatically. These should be added manually or you can write a wrapper function if you would like to simplify things (please notify me if you think you wrote one that should be part of the module).

Also all the module settings are gone except the "Load scripts" checkbox because all other settings became useless after the rewrite.

The new syntax looks like this (here with a helper to add a noscript tag for no-js fallback):

<?php $img = $page->featured_image; ?>

<img data-srcset="<?php echo $img->srcset('200x300,*2,*3'); ?>" class="lazyload" data-sizes="auto" alt="" />

    <img src="<?php echo $img->srcsetUrls[0]; ?>" />

The main change is that you can easily tell what image sizes (sets) you need ("200x300,*2,*3" in the above example). Of course you can use WxH values for each set or use divisors too. What's more you don't have to start with the lowest image size, eg. "1200x900, /2, /4" is perfectly fine. 

  • Like 4

Share this post

Link to post
Share on other sites

Thanks for the update, Something to possible consider -  maybe a field in the module settings where the user can type in the url segment to identify that the page is an AMP page and from there replace the <img> tage with the <amp img ></amp> tag?

Share this post

Link to post
Share on other sites

The module doesn't output the img tag, only the value for the srcset attribute so I don't see how this feature could be implemented.

Share this post

Link to post
Share on other sites

Maybe that my question is a bit OT. As the new modules version works perfect! ^-^

My question is related to data-bgset. I want to show an image covering the whole vieport. Therefor I use a div with background image. The css for the div is:

        position: relative !important;
        display: block;
        height: 100vh;
        background-position: 50% 50%;
        background-repeat: no-repeat;
        background-size: cover;

My list is defined like: 600x0, 1200x0, 1800x0

Related to the background-size: cover, I believe, I get always the image displayed what is one step to small from the list, because they get stretched by css, to cover the viewport.

Can someone tell me how to solve this with MarkupSrcSet?

Share this post

Link to post
Share on other sites

Ok, I may add a workaround to my own question:

I have found out, that, for what ever reason, the largest variation never was fetched from the server !! ??

With my example form above, the largest variation fetched was the 1200x0. Then, with adding a 1801x0 to the list, the 1800x0 was fetched as largest. So, not sure why this behave is.

Has anyone else seen this for bg-sets?
Besides the workaround, it isn't useful to get the HDs filled up with (regularly) unnessecary large variations.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      I got tired of having to open the link dialog in CKEditor in order to check where a link is pointing to, so made this simple plugin.
      Link Hover
      A plugin for CKEditor. Shows the href attribute of a link in a tooltip when the link is hovered. This saves you from having to open the link dialog in order to check where a link points to.

      This readme assumes installation in ProcessWire CMS.
      The plugin folder must be named "linkhover" – if necessary, rename the folder to remove the "-master" suffix added by GitHub. Copy the "linkhover" folder to /site/modules/InputfieldCKEditor/plugins/
      In the field settings for each CKEditor field that you want to activate the plugin for, check the "linkhover" checkbox at Input > Plugins > Extra Plugins
    • By neosin
      I've been reading through the tutorials and have created an admin module based on the ProcessHello example module.
      I have a few questions regarding how to do a few things with the module that are not obvious or covered by the processhello tutorial.
      Outline of expected module functionality:
      The custom module admin setup page should contain a list of its editable pages. CMS users will be able to add/edit/delete pages of this module. The modules editable pages use the same defined fields. The editable pages data will need to be available for use by another custom module. This custom module (called "Stream Encoders") will handle creating/updating/deleting of "Stream Encoders".
      The encoders contain various fields such as encoder name, operational status (is it on or off) and brightcove asset ID
      A second module in "admin>setup" called "Video Streams" will handle creating/updating/deleting/scheduling of "Video Streams".
      Each video stream belongs to a video encoder and uses some of the settings from the encoder selected, such as the encoder title and the brightcove asset ID which on the frontend are used to display the video stream.
      My noob questions:
      Since they are not "pages" in the navigation tree, how do I define these "encoders" to add them to the custom stream encoders module? I don't believe my custom modules should be under "Setup", is it possible to have custom menus in the admin? It's fine if they can't but it would be more intuitive if they had their own menus in the admin instead of living under "Setup". Without having a specific page on the frontend for video streams, how would I access the data for a specific video stream from the home page? for example if I wanted to display a specific or random video stream in a sidebar on the homepage. Are there any tutorials on using scheduling with custom modules? The video streams can be scheduled or turned on/off as desired by the CMS users. thank you in advance
    • By BitPoet
      The module has been lying around on GitHub for some time now, so I thought I'd give it its own forum topic so I can give it a module list entry.
      Symmetric encryption for text based fields (supports multi language fields).
      Module page.
      Link to the GitHub repo.
      This module adds an encryption option to all text fields (and those derived from FieldtypeText).
      Field contents are encrypted using a symmetric key when a page is saved and decrypted when loaded from the database.
      The module by default uses sodium (if loaded) in PHP versions >= 7.2, otherwise it falls back to the bundled phpseclib.
      Multi-Language fields are supported too.
      Setting a field to encrypted and saving values in those fields is a one-way road!
      Once encrypted, the contents cannot be unencrypted without writing a program to do so. Disabling the encryption option on a field after the fact gets you encrypted "garbage".
      Download the zipped module through the green button at the top right of the GitHub repo or (once available there) from the official PW module repository Extract in its own directory under site/modules. In the backend, click "Modules" -> "Refresh", then install "Symmetric Encryption for Text Fields". Go to module settings. An appropriately sized, random key will be generated if this is your first use. Copy the supplied entry into site/config.php Add fields or configure already present fields. On the "Details" tab you can enable encryption for the field in question Edit a page with such a field, enter a value there, save and enjoy Existing, unencrypted values are left untouched until a new value is saved. That way, you can do a smooth upgrade to encryption, but you have to save all pre-populated pages to have their values encrypted in the database. Thus it is recommended to avoid adding encryption to already populated fields.
      Advanced Usage
      You can hook after SymmetricEncryptedText::loadKey to retrieve your key from somewhere else, e.g. a different server.
    • By BitPoet
      After building the ProcessMentions module and another autocomplete module for images, I found that I am going to need even more of these, but things were going to get repetitive. So I refactored the whole thing into a basic autocompletion module and individual "actions".
      The result is Autocomplete for CKEditor (GitHub).
      To try out,
      Install the module and actions

        Enable actions in the settings of any CKEditor field

        Edit a page with this field, type "@" and some characters for the  and enjoy
      There are still a few things I need to implement. ATM, it only supports single characters as triggers for the autocomplete. I'd like to change that to combinations so I don't run out of special characters at some point. I also have to add a few more configuration options (like search only at the beginning or also in the middle of the searched string). The documentation for custom styling also needs some work.
      I have tried to keep things generic. Implementing your own actions should be quite straight forward. The README at GitHub illustrates the main steps and the supplied action classes have inline documentation. I would love to get some feedback or even see some third party InlineCompleteAction implementations.
    • By Inxentas
      I love the option to export fields via the CMS, and wondered about using that export data in a module. Basicly, I'd want to configure a field using the CMS and then paste it's export data in the module code as a string, or save it in a seperate file I can read from the module code. Once I have that string as a variable or file, I'd want to run the same code the import option does... but then from my module code's install method!
      Is that possible? It would save a lot of time configuring fields through the API.