HTML (on profile field)

Blocks ::: block_profilespecifichtml
Maintained by Valery Fremaux
This simple bloc allows outputing HTML content in a bloc with several versions based onthe check of custom profile fields values (2 checks)
Latest release:
59 sites
5 fans
Current versions available: 12

This bloc is a clone of the standard HTML block but provides custom profile field control over the version of content which is displayed.

Up to 2 fields can be checked and combined with logical (AND, OR, XOR) operators.

The Moodle 2.x versions are the result of the French state level project "ENTLibre 2.0" Of the National Funding program "Investissement d'Avenir"


Valery Fremaux (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS


  • Sat, Jun 27, 2015, 3:42 AM
    Hi Valery, the link to "More documentation on this plugin" results in a 404 error.

    Can you give me a sample scenario of when I might want to use this plugin?

    Best regards,

  • Thu, Nov 5, 2015, 6:35 PM
    Hi Michael - a scenerio for our institution is to show relevant and personalized news/content for staff (and students) in a particular department. Havn't installed yet, running 2.9 so will see how it works and maybe make a few mods.
  • Thu, Apr 21, 2016, 6:35 AM
    Hi, I love the concept, but unfortunately I am having trouble with it on 2.7

    We have a custom profile field "Campus", since all of our campuses aare serviced by a single LMS. I had an embedded slideshow for each campus, and wanted users to only see theirs, so I made a block for each campus and used the rule "Campus = [campus name]". No content for all users, just content for matching users. The first two campuses worked perfectly, but the third group was able to see all three slideshows. I tried various other ways of doing the rule, including using the "Like" operator, but every rule either let the third campus see all of the slideshows or no slideshow at all.

    The only thing that I can think of is that while the first two campuses are a single word, "Austin" and "Boulder", the third campus is two words with a special character: "Boulder - Online". Since this profile field is a multi-select, If tried making a new selection "Boulder Online", but when I set a user to have that as their campus, the slideshow was not visible at all. So I don't know if there's a second issue going on with caching the profile field setting or something?

    Anyone have any thoughts on this, please let me know!
  • Thu, Apr 21, 2016, 8:36 PM
    Hi Nicolas

    Actually i do not tried what happens in table mdl_user_profile_data when a field is multiselect. The profile field resolution uses an internal eval() statement to build the comparison expression. I would not believe (before testing) that a hyphen would break the = or event Regular expression matching. I will have some tests ASAP on the use case.
  • Sat, Apr 23, 2016, 12:52 AM

    I did some additional testing. I switched to using the "Institution" field to avoid any possible problems with using a multi-select profile field, or a custom field in general. Here are the inputs and what I saw:

    institution result
    Austin User sees only correct blocks
    Boulder User sees only correct blocks
    Boulder - Online User sees all blocks
    Boulder Online User sees no blocks
    BoulderOnline User sees only correct blocks
    Online User sees only correct blocks
    Isla Nublar User sees no blocks

    So it looks to me like the hyphens are indeed breaking something, and causing users to see all blocks using that user field. If there is a space, but no hyphen, then the opposite happens, and the user does not even see the blocks that they should based on the field rules. I am using this on Moodle 2.7, so I don't know if there was a change in core code from 2.6 that would've caused this?

    I'm going to just switch to using Institution names without spaces and special characters (thank goodness for bulk user actions and CSV uploads!), but I thought I'd share my findings in case you want to update the block for the newer Moodle releases.
  • Mon, Apr 9, 2018, 2:15 PM
    Hi Valery,

    Thanks for sharing such nice block.
    Is it possible to hide block to unmatched users using this block.
  • Mon, Apr 9, 2018, 2:40 PM
    hi Valery,

    got solutions, if we don't write message for unmatched users then its not appearing . Thanks once again.
  • Wed, Oct 24, 2018, 7:37 PM
    hi Valery,

    I can't seem to get this to work on Moodle33.

    No matter if I use a custom field or any standard field I get this error "Exception - syntax error, unexpected '==' (T_IS_EQUAL) ". The fiekd name does not have a - in it. Any ideas please? It will be a great solution if I can get this working.

    many thanks\merci

  • Tue, Oct 30, 2018, 8:46 PM
    Hi again, we applied the latest githib version rather than the last downloadable plugin version as it was more up to date and the error disappeared. Unfortunately none of the custom or standard profile fields seem to pick up on the conditional formula i.e. no users match even though they have the field values. Oh well.
  • Thu, Dec 12, 2019, 8:08 AM
    Hi Ciaran,

    If you still having issues with "Exception - syntax error, unexpected '==' (T_IS_EQUAL) " then alter the code in block_profilespecifichtml.php line 109. You need to add if(!empty($uservalue)){

    if ($this->config->op1 == '~=') {
    $expr = "\$res1 = preg_match('/{$this->config->value1}/', '{$uservalue}'}) ;";
    } else {
    $expr = "\$res1 = {$uservalue} {$this->config->op1} '{$this->config->value1}' ;";

Please login to post comments