WBCE CMS Forum

WBCE CMS – Way Better Content Editing.

Du bist nicht angemeldet.

#1 07.05.2019 04:23:32

losttrip
Mitglied

Issues with OneForAll in optional content block

I've run into a problem with a OFA (oneforall) module section in a block using has_block_content_1

This in my template info.php:

$block[5]   = 'Promo Section';

I have this in my template index.php file:

<?php if (has_block_content(5)) { ?>
<?php page_content(5); ?>
<?php } ?>

All works fine if I add a WYSIWYG section into the block 5 Promo Section.
But when I add a OFA (named hrhevents) into the block 5, I get this:

Fatal error: Uncaught Error: Call to a member function numRows() on null in /home/mysite/public_html/modules/hrhevents/view_overview.php:32 Stack trace: #0 /home/mysite/public_html/modules/hrhevents/view.php(80): include() #1 /home/mysite/public_html/framework/frontend.functions.php(308): require('/home/mysite/...') #2 /home/mysite/public_html/templates/mytemplate/index.php(123): page_content(5) #3 /home/mysite/public_html/index.php(81): require('/home/mysite/...') #4 {main} thrown in /home/mysite/public_html/modules/hrhevents/view_overview.php on line 32

If I show all notices, I also get HUNDREDS of undefined variable language notices and these others eg.,:

Notice: Undefined variable: mod_name in /home/mysite/public_html/modules/hrhevents/languages/EN.php on line 151

Notice: Undefined variable: set_scheduling in /home/mysite/public_html/modules/hrhevents/view.php on line 66

Notice: Undefined variable: mod_name in /home/mysite/public_html/modules/hrhevents/view.php on line 75

Notice: Undefined variable: mod_name in /home/mysite/public_html/modules/hrhevents/view.php on line 76

Notice: Undefined variable: mod_name in /home/mysite/public_html/modules/hrhevents/view_overview.php on line 31

Any help would be appreciated.

Offline

#2 07.05.2019 23:47:27

stefanek
Developer

Re: Issues with OneForAll in optional content block

I wonder if the issue stems from the has_block_content snippet or rather from the OFA module itself.
What happens if you leave out the has_block_content call in your code above and use only the page_content(5) call instead?

Kind regards,
Christian


“Success is the progressive realization of a worthy ideal.” ― Earl Nightingale

Offline

#3 08.05.2019 01:54:36

losttrip
Mitglied

Re: Issues with OneForAll in optional content block

The OFA works as expected if I just have:

<?php page_content(5); ?>

To test, I added the has_block_content to a couple of my local test sites and then installed a couple of different OFA modules (one in each) and I get the same Fatal Error and hundreds of notices in both.

Would anyone else be able to run a test?

Beitrag geändert von losttrip (08.05.2019 02:13:26)

Offline

#4 08.05.2019 05:48:12

florian
Administrator

Re: Issues with OneForAll in optional content block

I had run several tests yesterday morning. The error appears, when using the has_block_content snippet or the code I posted in https://forum.wbce.org/viewtopic.php?pid=22226#p22226 in the first code box.
It does not appear when using the combination of fetching the content into blocks seperately from displaying them as described in the other code boxes in the mentioned post. This kind of code is used for example in the template "zweinullig".

Beside of this, I'm not sure that even if it would be somehow possible to get OfA working with has_block_content, the result would be what you expected. First, the moment you set up an OfA block there, it would always have content, no matter if there are OfA-entries to display or not. Secondly, if you use it to link to / display OfA entry detail pages, the entry details would appear in the hrhevents area too, not as single pages without any other content.

So the or a solution might be to use another module, i.e. Itemz, which works flawlessly with has_block_content.
(There appear two notices too, but only if there are no items to display, and this is an itemz issue and is not caused by has_block_content.)

Beitrag geändert von florian (08.05.2019 05:49:49)


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#5 08.05.2019 21:47:41

losttrip
Mitglied

Re: Issues with OneForAll in optional content block

Thank you for your time and detailed explanation.  I will try both working approaches and see which works best for my needs.

Offline

#6 09.05.2019 17:58:53

losttrip
Mitglied

Re: Issues with OneForAll in optional content block

Well... this has been a fun exercise.  Unfortunately, none of the workflows have have provided the results I am looking for.
Even with Items, AND using your second code example, if I have no items, it still shows the Itemz section html (Group name etc.).  If I delete the Group, it still shows content "No Groups".

Maybe I am not asking the right question, or looking for the wrong approach.

Here is an example of how my page is set up:
<?php page_content(1); ?>
<?php page_content(2); ?>
<?php page_content(3); ?>                           

Here is what I am trying to accomplish.  If possible, I would prefer to do this using OFA.
<?php page_content(3); ?>        contains the OFA section.
When I disable all the items in the OFA, I do not want to see ANYTHING in that section.
Right now, even with your second code suggestion, it still shows "None Found" and the surrounding CSS styles (which is a coloured box).

Offline

#7 10.05.2019 06:22:17

florian
Administrator

Re: Issues with OneForAll in optional content block

To use OfA, try the following.
1) It does not work with has_block_content, so apply the following changes to your template.
Before the </head> tag, add the following php code:

<?php  require_once __DIR__.'/info.php';
        foreach($block as $k=>$v){
            ob_start(); 
            page_content($k); 
            $block[$k] = ob_get_clean();
        }
        
        
        if(defined('MODULES_BLOCK2') AND MODULES_BLOCK2 != '') { 
            $block[2] .= MODULES_BLOCK2;
        }
?>

2) If you do not need the opportunity to show blocks 1/2 according to their contents, replace

<?php page_content(1); ?>
<?php page_content(2); ?>

with

<?php echo $block[1]; ?>
<?php echo $block[2]; ?>

3) For the optional 3rd block, use the following code:

<?php if (strlen($block[3])>200) { ?>
your html code before the block.....
<?php echo $block[3]; ?>
your html code behind the block.....
<?php } ?>

The amount of 200 characters is sufficient to suppress the empty div, the "none found" and the section anchor which are usually generated. When there is an item, there are more than 200 characters, and the block will be displayed.

Beitrag geändert von florian (11.05.2019 07:56:49)


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#8 11.05.2019 00:07:55

losttrip
Mitglied

Re: Issues with OneForAll in optional content block

I tried this, and it works (as far as I have tested), Thank You!

I did have to adjust the block numbers in your first and last code sample from 2 and 4 to 3 to match the block I was trying to test for.  I hope that was the correct thing to do.  The code as you supplied did not work, and I suspected the block numbers just got jumbled as you were working through a solution.  If I am incorrect, please let me know.

I did have to increase the minimum strlen to >489
Not sure if that will cause me issues, but it would not hide the block, unless I did that.

Is this code change necessary:
from
<?php page_content(1); ?>
to
<?php echo $block[1]; ?>

I did not make that change, as I want to keep the changes as minimal as possible.  What is the purpose of this proposed change?

If you feel this solution might be a satisfactory workflow for others, perhaps this part of the thread could be moved to the OFA forum.

Thank again.

Offline

#9 11.05.2019 00:27:36

losttrip
Mitglied

Re: Issues with OneForAll in optional content block

Wait...
Maybe my assumptions on changes to your code were not wise, or the code work-around has other implecations.

I just found the exact same issues (hundreds of notices and the Fatal Error) on another page or the same website, which has a totally different OFA module placed in block 1 (main block) and has lots of enabled items.
The notices and fatal error go away and the items show, ONLY if I move that section to Block 3

Any ideas?

Offline

#10 11.05.2019 05:52:00

florian
Administrator

Re: Issues with OneForAll in optional content block

You were right, I had an error in the code example I have posted, I have corrected it now. I'm sorry.
In the loop there should ofcourse appear the contents of the block which length is checked.
The amount of characters probably depends to the code which is placed in the module's header/footer loop.

Beside of that mistake, the code worked. I do not understand why you are so reluctant to use the proposed solution.
I don't know why your mixed code does cause issues. Attach the index.php of your template here, and I might have a look on it.


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#11 11.05.2019 06:19:24

losttrip
Mitglied

Re: Issues with OneForAll in optional content block

I am not reluctant at all.  I said I tried your code as is and it didn't work, I assumed because of the block number confusion.  I'm not sure how I am coming across as reluctant, but it's not intentional.

I now just tried your revised code, even though the numbers still seem strange to me, and it too does not work as expected.

I'm confused as to why you address block 2:

if(defined('MODULES_BLOCK2') AND MODULES_BLOCK2 != '') { 
            $block[2] .= MODULES_BLOCK2;

And then block 4:

<?php if (strlen($block[4])>200) { ?>
your html code before the block.....
<?php echo $block[4]; ?>
your html code behind the block.....
<?php } ?>

When I only have three blocks in my info example in my post.

Here is an example of how my page is set up:
<?php page_content(1); ?>
<?php page_content(2); ?>
<?php page_content(3); ?>                           

Here is what I am trying to accomplish.  If possible, I would prefer to do this using OFA.
<?php page_content(3); ?>        contains the OFA section.

The only additional question I had was:

Is this code change necessary, or optional:
from
<?php page_content(1); ?>
to
<?php echo $block[1]; ?>

and

<?php page_content(2); ?>
to
<?php echo $block[2]; ?>

What is the purpose of this proposed change?

I asked this because you said:

2) If you do not need the opportunity to show blocks 1/2 according to their contents, replace

Which made it sound optional.  I guess I just don't understand.  When I make the change to <?php echo $block[2]; ?>, the fatal error and notices on the other pages are fixed.

Beitrag geändert von losttrip (11.05.2019 06:31:21)

Offline

#12 11.05.2019 08:20:04

florian
Administrator

Re: Issues with OneForAll in optional content block

Sorry, my mistake, indeed I had adressed the wrong blocks in my code example. So I corrected it again.

This

if(defined('MODULES_BLOCK2') AND MODULES_BLOCK2 != '') { 
            $block[2] .= MODULES_BLOCK2;

is optional, it's common practice in nearly all newer templates as a preparation to use the 2nd Topics block functionality (e.g. place parts of contents which are generated by the Topics module in another section of the site). You can delete this.

The issue with OfA is caused, because the page_content function is called twice, when instead of echo $block[3] page_content(3) is used: the first time  at the top of the content (as part of the foreach loop) , the 2nd time in the body (where it was situated already before). That way, some module specific constants or variables seem not to be initialized the right way, or the module fails to load required parts.

So to avoid this issues, replace the function calls
<?php page_content(1); ?>
<?php page_content(2); ?>
<?php page_content(3); ?>

with the variable (array) echoing
<?php echo $block[1]; ?>
<?php echo $block[2]; ?>
<?php echo $block[3]; ?>

The "If" in my former point 2) was meant as "You do not need the if  (strlen($block[x])<y) code there, if these blocks should always be displayed ". 
The replacement of the function is mandatory, but I must confess, I didn't expect and had not checked yesterday, if this would cause any problems in case it would no have been done. I just thought it would be less "clean / elegant" if having the contents of the blocks already written into an array, but using the page_content function nevertheless.


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#13 11.05.2019 15:33:37

losttrip
Mitglied

Re: Issues with OneForAll in optional content block

Thank you for the solution and explanation.

This is working perfectly now.  Much appreciated.

Offline

Fußzeile des Forums

up